API guide

Chat

POST /v1/chat/completions is the single entry point for text models, whichever vendor made the model.

Request

The body is the standard chat completions body: model and messages are required.

{
  "model": "MODEL_ID",
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user", "content": "Hello" }
  ]
}

Response and usage

The response is a standard chat.completion object (shortened below). Billing follows the token counts the model reports in usage.

{
  "object": "chat.completion",
  "model": "MODEL_ID",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "..." },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": <int>, "completion_tokens": <int> }
}

Streaming

Set "stream": true to receive server-sent events. Add stream_options.include_usage to get token usage in the stream.

curl https://api.novapi.ai/v1/chat/completions -N \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_ID",
    "stream": true,
    "stream_options": { "include_usage": true },
    "messages": [{ "role": "user", "content": "Hello" }]
  }'

Errors you may see

  • 401 invalid_api_key: missing or invalid key.
  • 400 model_not_found: the model is not currently available.
  • 402 insufficient_quota: balance too low (a balance under 0.1 credits is rejected).
  • 403 model_not_allowed: the key's model allowlist does not include the model.
  • 502 upstream_error / upstream_auth_error: the provider call failed. Provider credential problems are reported generically and never echoed.

Counting tokens

POST /v1/chat/completions/count_tokens returns a local estimate (input_tokens, estimated: true). It is not billed and errs high.

See also