Skip to content
Hayonix

Quickstarts

Your first inference call

Send a chat completion to an open model with curl, the SDKs or the official OpenAI clients, then stream the answer token by token.

The inference API follows the OpenAI API, so you can use the SDKs below or keep the OpenAI client you already have and change two settings: the base URL and the key.

Before you start

You need an API key with the inference:invoke scope and the environment from Setup:

Environment variables
VariableValue
API_KEYsk_… (your project API key)
API_BASE_URLhttps://api.hayonix.ai/v1
INFERENCE_BASE_URLhttps://api.hayonix.ai/v1

The samples read the model from MODEL. GET /v1/models lists every model your key can use; pick one whose serving field is true, because the catalog also lists models that have no replica running right now (base models for fine-tuning, for example).

Send a chat completion

With the SDKs, client.openai() returns the official OpenAI client already pointed at the inference base URL with your key.

jq -n --arg model "$MODEL" '{
  model: $model,
  messages: [{role: "user", content: "Name three uses for a GPU in one sentence."}],
  max_completion_tokens: 64
}' |
curl -sS "$INFERENCE_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d @- |
jq -r '"reply: " + (.choices[0].message.content // "" | gsub("^\\s+|\\s+$"; "")), "tokens: \(.usage.total_tokens)"'

The response is the OpenAI chat completion object. usage holds the token counts you are billed for, as the engine reported them.

Use the OpenAI client directly

If you do not want our SDK, construct the OpenAI client yourself with our base URL:

import OpenAI from 'openai';

const model = process.env.MODEL ?? 'qwen/qwen2.5-0.5b-instruct';

const plain = new OpenAI({
  apiKey: process.env.API_KEY,
  baseURL: process.env.INFERENCE_BASE_URL,
});
const again = await plain.chat.completions.create({
  model,
  messages: [{ role: 'user', content: 'Say hello in five words.' }],
  max_completion_tokens: 32,
});
console.log('reply:', again.choices[0]?.message.content?.trim() ?? '');

Stream the answer

Set stream: true to receive server-sent events as tokens are generated. The stream ends with data: [DONE].

jq -n --arg model "$MODEL" '{
  model: $model,
  messages: [{role: "user", content: "Count from one to five."}],
  max_completion_tokens: 64,
  stream: true
}' |
curl -sS -N "$INFERENCE_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d @- |
sed -un 's/^data: //p' | grep --line-buffered -v '^\[DONE\]$' |
jq -j '.choices[0].delta.content // empty'
echo

What a request costs

Each request reserves credit for its worst case (the prompt plus the most tokens it may generate) before it runs and settles at the real token count when it ends, so an out-of-credit key gets 402 up front instead of a surprise bill. A stream you cut off is billed for the prompt and the tokens already sent. See Billing and credit.

Next