Chat Completions API
DeepNexus exposes an OpenAI-compatible API. Any SDK or tool that supports a custom OpenAI base URL works unchanged.
| Item | Value |
|---|---|
| Base URL | http://localhost:3000/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 http://localhost:3000/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 http://localhost:3000/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 http://localhost:3000/v1/models -H "Authorization: Bearer $DEEPNEXUS_API_KEY"
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 |