RunAi is compatible with the OpenAI API specification. Specify the model in the model field of the request body; do not specify it through the URL path or a custom header.
pip install openai
# or
npm install openaicurl https://ai.runmailx.com/v1/chat/completions \
-H "Authorization: Bearer $RUNAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek/deepseek-v4.1-flash",
"messages": [{"role": "user", "content": "Hello"}]
}'Every request must include a Bearer key in the header:Authorization: Bearer sk-runai-xxxxxxxx. Keys are created per project and can each have their own budget, model allowlist and IP allowlist. If a key is exposed, delete it in the console; it ceases to work immediately.
Do not expose keys in browser code or public repositories. If your front end needs a direct connection, forward requests through your own server.
POST /v1/chat/completions, and the request body matches OpenAI. The model field in the response echoes the platform model name sent in the request, so you can verify that the model has not been substituted.
from openai import OpenAI
client = OpenAI(
api_key="sk-runai-xxxxxxxx",
base_url="https://ai.runmailx.com/v1",
)
resp = client.chat.completions.create(
model="qwen/qwen3.8-flash",
messages=[
{"role": "system", "content": "You are a concise technical assistant"},
{"role": "user", "content": "Explain how context caching is billed"},
],
temperature=0.7,
)
print(resp.model)
print(resp.usage)model — Platform model identifier. Required.messages — Array of chat messages; supports system / user / assistant.temperature, top_p, max_tokens — Passed through according to model capabilities.tools, response_format — Applies only to models that declare support.stream — When enabled, returns incremental content over SSE.Streaming requests are returned as text/event-stream, in the same format as OpenAI. If an error occurs before the first byte, the request is retried on another available route; content already emitted is not retried and is not charged twice.
stream = client.chat.completions.create(
model="deepseek/deepseek-v4.1-flash",
messages=[{"role": "user", "content": "Write a 200-word product description"}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)Call POST /v1/embeddings to create text embeddings. The model is passed in the request body and the response matches the OpenAI schema, so you can reuse existing retrieval, clustering and deduplication pipelines.
resp = client.embeddings.create(
model="bge/bge-m3",
input=["第一段文本", "第二段文本"],
)
print(len(resp.data))
print(len(resp.data[0].embedding))Call POST /v1/images/generations to generate images from a prompt. Returned image URLs expire and must be regenerated; you can also request b64_json to receive the image inline.
resp = client.images.generate(
model="bytedance/seedream-4.0",
prompt="A clean product photo of a ceramic coffee cup on a wooden desk",
size="1024x1024",
)
print(resp.data[0].url)Images are billed per image; the count and amount are recorded in the request log.
Call GET /v1/models to list the models available to the current account. The response includes context length, input and output modalities, and whether vision input is supported.
curl https://ai.runmailx.com/v1/models \
-H "Authorization: Bearer $RUNAI_API_KEY"Limits are tracked per API key and per organization. When a limit is reached the API returns 429 with a Retry-After header; clients should back off for that period.
Migration requires two changes; your application code and message structure stay the same:
base_url to https://ai.runmailx.com/v1.api_key with your platform key.For tools such as LangChain, LlamaIndex, Cursor, Cline and NextChat, enter the same address as a custom API base URL. If the tool requires a full path, use /v1/chat/completions.
Error responses follow the OpenAI structure and include code and request_id:
{
"error": {
"message": "model is required in request body",
"type": "invalid_request_error",
"code": "model_required",
"request_id": "req_01J8X2K9Q7"
}
}| code | HTTP | Description |
|---|---|---|
| model_required | 400 | The model field is missing from the request body or is empty. |
| model_not_found | 404 | The model does not exist or is not available to this account. |
| unsupported_modality | 400 | The request contains an input modality the model does not support. |
| context_length_exceeded | 400 | The input exceeds the model's context limit. |
| invalid_api_key | 401 | The API key is invalid, deleted or expired. |
| insufficient_quota | 402 | Insufficient balance, and no free quota is available. |
| free_quota_exhausted | 429 | Free quota is exhausted; usage-based billing requires confirmation. |
| rate_limited | 429 | The concurrency or rate limit for the key or account has been exceeded. |
| risk_limited | 429 | A risk rule was triggered (for example, a burst of requests). Retry after the configured window. |
| upstream_unavailable | 503 | This model is currently unavailable; the request is not routed to another model. |
| upstream_timeout | 504 | The service did not return the first byte within the timeout. |
| internal_error | 500 | Internal platform error; quote the request_id when contacting support. |