POST /ai/chat/completions
Generate a response (chat completions compatible)
Scope ai:inference. Available on request: served only when Galon AI is open to the account (404 otherwise). No provider name is returned. Idempotency-Key required; reservation against the balance BEFORE the call (402 if the balance does not cover it). stream: true returns text/event-stream (usage in the last chunk) when the model publishes it; tools, response_format and images only for a model that publishes the capability.
API key (Bearer), on the public API endpoint.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
Idempotency-Key | header | string · required |
Request body
application/json
| Field | Type | Description |
|---|---|---|
model | string · required | |
messages | array<object> · required | |
max_tokens | integer | |
temperature | number | |
top_p | number | |
stop | any | |
stream | boolean | |
seed | integer | |
tools | array<object> | |
tool_choice | any | |
response_format | object |
Responses
| Status | Description | Body |
|---|---|---|
200 | Response in chat completions format (or SSE stream) | object |
400 | Unsupported field: code, field and message say what to correct | Error |
402 | Insufficient balance | Error |
403 | scope_missing | Error |
429 | Request quota reached | Error |
503 | model_temporarily_unavailable | Error |
401 | Key missing or invalid | Error |
Examples
curl
curl -X POST "$GALON_API_BASE/ai/chat/completions" \
-H "Authorization: Bearer $GALON_API_KEY" \
-H "Idempotency-Key: <unique-key>" \
-H "Content-Type: application/json" \
-d '{"model": "<id from GET /ai/models>", "messages": [{"role": "user", "content": "Hello"}]}'Node.js (SDK)
import { Galon } from "galon";
const galon = new Galon(process.env.GALON_API_KEY);
const result = await galon.ai.chat({"model": "<id from GET /ai/models>", "messages": [{"role": "user", "content": "Hello"}]}, { idempotencyKey: "<unique-key>" });Python (SDK)
from galon import Galon
galon = Galon() # reads GALON_API_KEY
result = galon.ai.chat({"model": "<id from GET /ai/models>", "messages": [{"role": "user", "content": "Hello"}]}, idempotency_key="<unique-key>")