Chat Completions
Generate text, returned in the familiar OpenAI response shape.
Implemented
Request
POST
/chat/completionsRequires the Authorization: Bearer apl_... header
| Field | Type | Description |
|---|---|---|
modelrequired | string | Public model ID from GET /models. |
messagesrequired | Message[] | Array of { role, content } where role is system | user | assistant. |
stream | false | Only false is accepted today. Sending true is rejected explicitly rather than silently returning a non-streamed body. |
Response
| Field | Type | Description |
|---|---|---|
choices[0].message.contentrequired | string | The generated content. |
usagerequired | object | prompt_tokens, completion_tokens, total_tokens. |
apilux.credit_chargedrequired | integer | Credits charged for this request. |
apilux.balance_afterrequired | integer | Wallet balance after the charge. |
Billing
By total tokens (input + output), priced per 1,000,000 tokens. Minimum 1 credit per successful request.
Examples
curl https://apilux.net/api/v1/chat/completions \
-H "Authorization: Bearer apl_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MODEL_ID",
"messages": [{ "role": "user", "content": "Xin chào" }]
}'const res = await fetch("https://apilux.net/api/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.APILUX_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "MODEL_ID",
messages: [{ role: "user", content: "Xin chào" }],
}),
});
const data = await res.json();
console.log(data.choices[0].message.content);import os, requests
res = requests.post(
"https://apilux.net/api/v1/chat/completions",
headers={
"Authorization": f"Bearer {os.environ['APILUX_API_KEY']}",
"Content-Type": "application/json",
},
json={
"model": "MODEL_ID",
"messages": [{"role": "user", "content": "Xin chào"}],
},
)
print(res.json()["choices"][0]["message"]["content"])Errors
| HTTP | Code | Meaning |
|---|---|---|
| 400 | invalid_request | Invalid body (missing field, wrong type, value out of range). |
| 401 | auth_missing_or_malformed | Missing Authorization header, or it is not in the Bearer apl_... form. |
| 401 | auth_invalid | The API key does not exist. |
| 401 | auth_revoked | The API key has been revoked. |
| 401 | auth_expired | The API key has expired. |
| 400 | unknown_model | The model does not exist on ApiLux. |
| 400 | capability_not_supported | The model exists but cannot be used on this endpoint (e.g. a text model on an image endpoint). |
| 503 | pricing_not_configured | The model is implemented but has no price configured on ApiLux yet. This is our state, not a client error. |
| 503 | model_disabled | The model is currently disabled. |
| 503 | model_temporarily_unavailable | The model is enabled and priced, but the upstream provider is not currently serving it. This is temporary and can clear on its own — the model reappears in GET /v1/models once the provider serves it again. You are not charged and no provider call is made. |
| 402 | insufficient_balance | Wallet balance is not enough for this request. |
| 429 | api_key_limit_exceeded | This API key hit a limit you configured yourself. The wallet still has funds — only this key is capped until the window resets. The response carries limit_type (spending | requests | tokens) and period (daily | monthly | lifetime). Token limits on text endpoints are measured from actual usage, so the total can exceed the limit by at most one request. |
| 503 | api_key_quota_reconciliation_required | An earlier text request on this same key has not been reconciled yet. The usual cause: the provider returned a successful result without token usage, so the token limit for that window can no longer be trusted and ApiLux stops rather than let the limit be exceeded silently. Retrying will not help until that is done — contact support. You are not charged for the blocked request, no provider call is made, and image/video endpoints are unaffected. |
| 502 | upstream_error | The model provider failed. You are not charged. |
| 504 | upstream_timeout | The provider did not respond in time. You are not charged. |
| 429 | upstream_rate_limited | Rate limited. Retry after a few seconds. |
Notes
The response carries an extra
apilux object beyond the OpenAI shape. OpenAI clients ignore unknown fields, so nothing breaks.