Chat Completions API
ModelTunnel exposes an OpenAI-compatible API. Any SDK or tool that supports a custom OpenAI base URL works unchanged.
| Item | Value |
|---|---|
| Base URL | https://modeltunnel.ai/v1 |
| Protocol | OpenAI Chat Completions |
| Format | application/json, UTF-8 |
| Streaming | Server-Sent Events (text/event-stream) |
Authentication
Create a key on the API page and send it in either header:
Authorization: Bearer sk-dn-...
x-api-key: sk-dn-...
Endpoints
| Method | Path | Description |
|---|---|---|
GET | /models | List models with pricing, context window and capabilities |
GET | /balance | Balance and plan of the account that owns the key |
POST | /chat/completions | Chat completion, streaming or non-streaming |
Create a chat completion
POST https://modeltunnel.ai/v1/chat/completions
| Field | Type | Description |
|---|---|---|
model | string | Model ID from Language Models, or auto |
messages | array | Conversation messages: system, user, assistant, tool |
stream | boolean | Stream tokens as SSE. Default false |
temperature | number | Sampling temperature, 0 – 2 |
top_p | number | Nucleus sampling |
max_tokens | integer | Maximum output tokens |
tools / tool_choice | array / string | Function calling, on models that support it |
response_format | object | {"type": "json_object"} for JSON mode |
Other OpenAI parameters are forwarded to the upstream model as-is.
Example
curl https://modeltunnel.ai/v1/chat/completions \
-H "Authorization: Bearer $DEEPNEXUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "What is x402?"}
],
"stream": true
}'
Response
{
"id": "chatcmpl-...",
"object": "chat.completion",
"model": "deepseek-v4.1-flash",
"choices": [{ "index": 0, "message": { "role": "assistant", "content": "..." }, "finish_reason": "stop" }],
"usage": { "prompt_tokens": 24, "completion_tokens": 85, "total_tokens": 109 }
}
When model is auto, the model field of the response shows the model that actually served the request.
Streaming
Each event is a chat.completion.chunk with a delta. The stream ends with data: [DONE].
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"x402 is"}}]}
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" an open"}}]}
data: [DONE]
Images
Models with vision support accept OpenAI-style image parts:
{
"role": "user",
"content": [
{ "type": "text", "text": "What is in this picture?" },
{ "type": "image_url", "image_url": { "url": "data:image/png;base64,..." } }
]
}
List models
curl https://modeltunnel.ai/v1/models -H "Authorization: Bearer $DEEPNEXUS_API_KEY"
Note: When
Authorization: Bearer <key>is provided, the API automatically filters models based on the permissions assigned to that API key and user, returning personalized models with your account's exact discounted rates.
Check balance
Query the remaining balance, raw platform credits, total usage, and active plan for the authenticated account.
GET https://modeltunnel.ai/v1/balance
Example Request
curl https://modeltunnel.ai/v1/balance \
-H "Authorization: Bearer $DEEPNEXUS_API_KEY"
Example Response
{
"object": "balance",
"currency": "USD",
"balance": 18.520000,
"credits": 18520000,
"total_available": 18.520000,
"total_used_usd": 3.480000,
"total_used_credits": 3480000,
"plan": "free"
}
| Field | Type | Description |
|---|---|---|
balance | number | Available account balance in USD (1 USD = 1,000,000 Credits) |
credits | integer | Available platform Credits |
total_available | number | Equivalent USD available |
total_used_usd | number | Cumulative spend in USD |
total_used_credits | integer | Cumulative spend in platform Credits |
plan | string | Active plan (free, pro, team) |
Ecosystem Compatibility: ModelTunnel also supports OneAPI / NewAPI endpoints
GET /v1/dashboard/billing/subscription,GET /v1/dashboard/billing/usage, and NextChat endpointGET /v1/user/balancefor seamless out-of-the-box integration with tools like NextChat, Cherry Studio, Chatbox, and LobeChat.
Errors
Errors use the OpenAI error shape: {"error": {"message": "..."}}. Upstream errors are passed through with their original status.
| Status | Meaning |
|---|---|
400 | Invalid request or unknown model |
401 | Missing or invalid API key |
402 | Insufficient balance — top up |
5xx | Upstream provider error — safe to retry with backoff |