Quick Start: Your First Inference
The easiest way to interact with the APUS AI service is by using our@apus/ai Lua library. It handles all the complex messaging and payment details for you, so you can call the AI in a single line of code.
Step 1: Get Credits
Before you start, you need Credits to pay for inference requests. During the AO Hackathon, we are providing free credits to all participants.- Join our Discord: [https://discord.gg/r3aQcJRH5A]
- Go to the
#hackathon-creditschannel. - Post your
aosprocess ID to receive your free credits.
Step 2: Load the Library
In youraos terminal, load the @apus/ai library into your process. We recommend using a package manager like apm. If you don’t have it, first run .load-blueprint apm.
Step 3: Run Your First Prompt
Now you can call the AI. The library will handle the rest.Using the @apus/ai Lua Library
While the Quick Start showed you the simplest way to get a response, the @apus/ai library offers more control over the inference process through advanced options and callbacks.
Setup
First, ensure the library is loaded in youraos process.
Core Functions
The library provides a clean, simple interface for all interactions with the APUS AI service.ApusAI.infer(prompt, options, callback)
This is the primary function for sending an inference request. It’s designed to be flexible, supporting both simple fire-and-forget calls and more complex, stateful interactions.
Parameters:
prompt(string): Required. The text prompt you want to send to the AI model.options(table): Optional. A json string of parameters to customize the inference request.session(string): An existing session ID to continue a previous conversation. If a session ID is not provided, a new one will be created for the first turn.reference(string): A custom unique ID for your request. If omitted, the library generates one automatically. This is useful for tracking your requests.- …(and any other runtime parameter like
temperature,max_tokens, etc.)
callback(err, res)(function): Optional. A function that will be called with the result.-
If
erris present, it will be a table containing error details (e.g.,{ message = "Insufficient credits" }). -
If successful,
reswill be a table containing the response: - If no callback is provided, the response or error is printed directly to the console.
-
If
string: The uniquereferenceID for the request, which can be used for tracking.
-
Simple prompt (like Quick Start):
-
Using a callback to handle the response programmatically:
-
Advanced call with runtime options and a session:
ApusAI.setRouter(routerProcess)
Overrides the default Router Process ID. Useful for testing or if the main router process changes.
Parameters:
routerProcess(string): The new AO Process ID to use as the router.