Introducing ModelTunnel AI Native Cloud: Better frontier models, faster runs, lower costs →

Chat Completions API

ModelTunnel exposes an OpenAI-compatible API. Any SDK or tool that supports a custom OpenAI base URL works unchanged.

ItemValue
Base URLhttps://modeltunnel.ai/v1
ProtocolOpenAI Chat Completions
Formatapplication/json, UTF-8
StreamingServer-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

MethodPathDescription
GET/modelsList models with pricing, context window and capabilities
GET/balanceBalance and plan of the account that owns the key
POST/chat/completionsChat completion, streaming or non-streaming

Create a chat completion

POST https://modeltunnel.ai/v1/chat/completions

FieldTypeDescription
modelstringModel ID from Language Models, or auto
messagesarrayConversation messages: system, user, assistant, tool
streambooleanStream tokens as SSE. Default false
temperaturenumberSampling temperature, 0 – 2
top_pnumberNucleus sampling
max_tokensintegerMaximum output tokens
tools / tool_choicearray / stringFunction calling, on models that support it
response_formatobject{"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"
}
FieldTypeDescription
balancenumberAvailable account balance in USD (1 USD = 1,000,000 Credits)
creditsintegerAvailable platform Credits
total_availablenumberEquivalent USD available
total_used_usdnumberCumulative spend in USD
total_used_creditsintegerCumulative spend in platform Credits
planstringActive plan (free, pro, team)

Ecosystem Compatibility: ModelTunnel also supports OneAPI / NewAPI endpoints GET /v1/dashboard/billing/subscription, GET /v1/dashboard/billing/usage, and NextChat endpoint GET /v1/user/balance for 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.

StatusMeaning
400Invalid request or unknown model
401Missing or invalid API key
402Insufficient balance — top up
5xxUpstream provider error — safe to retry with backoff
Chat Completions API · ModelTunnel