API Compatibility
Use the OpenAI, Responses, and Anthropic-compatible Runtime endpoints and understand UnieAI extensions, streaming metadata, and upstream differences.
UnieAI Runtime exposes an OpenAI-compatible interface. Most OpenAI SDK and HTTP clients need only a different base URL, API key, and model slug. Compatibility depends on the implemented endpoint and the selected base model's upstream capabilities; it is not a guarantee of complete feature parity with every OpenAI API.
Basic configuration
| Item | Value |
|---|---|
| Runtime Base URL | https://your-runtime-domain/v1 |
| Authentication | Authorization: Bearer YOUR_API_KEY |
| Model identifier | Base-model or custom-model slug |
An API key belongs to the personal account or project where it was created and does not grant additional model access.
curl https://your-runtime-domain/v1/chat/completions \
-H "Authorization: Bearer $UNIEAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"your-model-slug","messages":[{"role":"user","content":"Hello"}]}'Public endpoints
| Endpoint | Compatibility and purpose |
|---|---|
GET /v1/models | Models accessible to the key |
POST /v1/chat/completions | OpenAI Chat Completions with streaming |
POST /v1/responses | Common Responses text, image, and function-tool structures translated to Chat Completions |
POST /v1/messages | Anthropic Messages translation |
POST /v1/embeddings | Embeddings for models with embedding capability |
POST /v1/audio/transcriptions | Multipart transcription for a capable model |
POST /v1/audio/speech | Text-to-speech for a TTS-capable model |
POST /v1/parser | UnieAI document parsing |
POST /v1/kb/search | UnieAI KB Super full-text search |
POST /v1/feedback | Rating with optional custom-model memory creation |
GET /health | Runtime liveness, outside the /v1 prefix |
For some unimplemented POST /v1/* JSON or multipart endpoints, Runtime transparently forwards to the selected model's upstream. A valid key, a model, and a forwardable upstream connection are required.
Passthrough support and response shape belong to the upstream provider. Passthrough traffic currently bypasses Runtime wallet reservation and settlement. Do not treat it as a formally supported or metered UnieAI endpoint.
Model catalogue metadata
GET /v1/models includes context_size and context_window with the same token capacity configured on the base model. Custom models inherit their base model's capacity. When the capacity is unset or zero, both fields are null; the catalogue does not invent a fallback context limit.
Each entry also includes shutdown_date: an absolute ISO 8601 timestamp in UTC or null (the default). Administrators set or clear the date and time in the model editor, displayed in the platform timezone. At the deadline the model is disabled and new requests, including Agents using it as their base model, are refused. In-flight upstream calls are not forcibly interrupted; subsequent model calls, including later Agent steps, still obey the deadline. Affected users receive in-app notices 3 days, 1 day and 12 hours before shutdown and when service stops. When Google SMTP is configured, each affected user also receives email. Reminder delivery is deduplicated; failed emails remain queued for retry while applicable.
{
"id": "your-model-slug",
"context_size": 262144,
"context_window": 262144,
"shutdown_date": null
}Chat Completions
| Parameter | Meaning |
|---|---|
model | Required model slug |
messages | Required OpenAI message array |
stream | Uses SSE when true |
temperature | Randomness; range and default depend on the upstream model |
max_tokens | Maximum output; Runtime also recognizes max_completion_tokens and max_output_tokens |
top_p | Nucleus-sampling cumulative probability mass |
top_k | Keeps only the k most likely next tokens; not a native named OpenAI SDK argument |
stop | Stop string or list; upstream support varies |
tools / tool_choice | Function calling, subject to model and upstream support |
Non-standard fields can be accepted, ignored, or rejected upstream. Pass top_k through extra_body in the Python OpenAI SDK:
response = client.chat.completions.create(
model="your-model-slug",
messages=[{"role": "user", "content": "Propose three options"}],
temperature=0.7,
max_tokens=800,
extra_body={"top_k": 40},
)Qwen thinking
chat_template_kwargs.enable_thinking is specific to the Qwen base-model family. It applies to a Qwen base model and to a custom model built from a Qwen base model; family matching is case-insensitive.
{
"model": "your-qwen-based-model",
"messages": [{"role":"user","content":"Analyze this step by step"}],
"chat_template_kwargs": {"enable_thinking": true}
}trueexplicitly enables thinking.falseexplicitly disables it.- An explicit request value takes precedence over the platform or custom-model default for that request.
- A non-Qwen upstream can ignore or reject the field.
Streaming responses
stream: true uses text/event-stream. Standard text arrives in Chat Completions chunks and ends with data: [DONE].
A custom model can also emit UnieAI metadata chunks, including rag_metadata, rag_iteration_metadata, api_metadata, mcp_metadata, mysql_metadata, skills_metadata, memory_metadata, websearch_metadata, agent_metadata, and guardrail_metadata.
Text-only clients should ignore chunks without choices[].delta.content. Clients rendering citations, tool timelines, or guardrail decisions can parse the relevant metadata and should ignore unknown fields for forward compatibility.
Responses and Anthropic compatibility
Responses API
POST /v1/responses translates instructions, text and image input, function calls and outputs, temperature, top_p, and function tools. Responses built-in tool types without Chat Completions semantics, such as some web_search, local_shell, or custom tools, can be skipped.
Anthropic Messages
POST /v1/messages translates Anthropic messages, content blocks, tools, and tool choice into the internal Chat Completions flow. Stop reasons, usage, and streaming events are mapped back to Anthropic shapes, but provider-specific fields are not guaranteed to survive unchanged.
Response headers
| Header | Meaning |
|---|---|
x-request-id | Runtime request ID |
x-unieai-billing-amount-cents | Settled charge in cents |
x-unieai-billing-amount-micro-usd | Settled charge in micro-USD |
x-unieai-balance-after-cents | Post-settlement balance in cents |
x-unieai-balance-after-micro-usd | Post-settlement balance in micro-USD |
x-unieai-billing-currency | Billing currency |
x-unieai-guardrail-blocked | true when blocked by guardrails |
x-unieai-passthrough | 1 for an unimplemented endpoint forwarded upstream |
Not every response has every header, particularly errors, unbilled flows, and output guardrail decisions made after streaming starts.
Errors and troubleshooting
{"error":{"code":"unauthorized","message":"Invalid API key","request_id":"req_abc123","details":{}}}| HTTP status | Common cause |
|---|---|
400 | Invalid request shape or parameter |
401 | Missing, invalid, disabled, or expired key |
402 | Insufficient available wallet balance |
403 | The key's project or personal account cannot access the model or asset |
404 | Unknown model slug or endpoint |
429 | Key rate limit or period quota exhausted |
500 / 502 | Runtime, dependency, or upstream failure |
For Model not found, put the slug shown on the custom model's Overview in model, not its display name. Request logs are under Operate → Request logs.
Related documentation
API keys, project or personal account scope, and the Default Key
Obtain a Default Key or create an application key, verify model access, and diagnose authentication failures.
Error Handling and Reporting
How Studio presents failures at each layer, the error format and status codes its APIs return, what each error code means, and what to hand to a platform administrator.