API reference

Create chat completion

POST /v1/chat/completions generates the next assistant message for a conversation, as JSON or as a stream.

On this page
POSThttps://api.larasrouter.com/v1/chat/completions

Generates the next assistant message for a conversation, in the OpenAI Chat Completions format. Supports streaming, tool calling, and JSON output.

Authentication
Send the key in either header:Authorization: Bearer lr_live_…x-api-key: lr_live_…
Content type
application/json

Request body

  • modelstringrequired

    Model ID. The only accepted value is deepseek-flash.

  • messagesarrayrequired

    The conversation so far, oldest first.

    • rolestringrequired

      system, user, assistant, or tool.

    • contentstring | array | nullrequired

      The message text, or an array of {"type": "text"} parts. Image parts are rejected with 400 unsupported_content. May be null on an assistant message that only carries tool_calls.

    • tool_callsarray

      On an assistant message: the tool calls the model made, sent back unchanged.

    • tool_call_idstring

      On a tool message: the id of the tool call this result answers.

  • max_tokensinteger

    Output cap, 1 to 384,000. Defaults to 8,192 when omitted. A larger value is rejected with 400 max_tokens_exceeded, never silently reduced. Reasoning tokens count toward it.

  • max_completion_tokensinteger

    Alias of max_tokens. If you send both, the smaller value applies.

  • streamboolean

    Send the response as Server-Sent Events. Defaults to false.

  • stream_optionsobject

    Streaming options.

    • include_usageboolean

      Send a final chunk with token usage before [DONE].

  • toolsarray

    Function definitions the model may call: {"type": "function", "function": {name, description, parameters}}.

  • tool_choicestring | object

    auto, none, required, or a specific function.

  • response_formatobject

    {"type": "json_object"} makes the model return a valid JSON object.

  • temperature, top_p, stop, presence_penalty, frequency_penalty—

    Sampling parameters, forwarded to the model unchanged.

Example request

curl https://api.larasrouter.com/v1/chat/completions \
  -H "Authorization: Bearer $LARAS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-flash",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Name three uses of a hash map."}
    ],
    "max_tokens": 1024
  }'

Response body

  • idstring

    Completion ID.

  • objectstring

    chat.completion, or chat.completion.chunk for stream chunks.

  • createdinteger

    Unix timestamp in seconds.

  • modelstring

    The model that answered.

  • choicesarray

    One choice.

    • message.contentstring | null

      The answer text.

    • message.reasoning_contentstring | null

      The model’s reasoning, when it produced any. Billed as output.

    • message.tool_callsarray

      Tool calls the model wants you to run.

    • finish_reasonstring

      stop, length (output cap reached), or tool_calls.

  • usageobject

    Token counts the charge is computed from.

    • prompt_tokensinteger

      All input tokens.

    • prompt_cache_hit_tokensinteger

      Input tokens served from cache, billed at $0.010 / 1M.

    • prompt_cache_miss_tokensinteger

      Input tokens not in cache, billed at $0.400 / 1M.

    • completion_tokensinteger

      Output tokens, reasoning included, billed at $1.600 / 1M.

    • total_tokensinteger

      Input plus output.

200 OK
{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "created": 1760241600,
  "model": "deepseek-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "1. Caching results by key…",
        "reasoning_content": "The user wants three uses…"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 180,
    "total_tokens": 204,
    "prompt_cache_hit_tokens": 0,
    "prompt_cache_miss_tokens": 24
  }
}

Streaming

With "stream": true the response is a stream of chat.completion.chunk events, ending with data: [DONE]. Set stream_options.include_usage to receive token usage in a final chunk. See Streaming.

text/event-stream
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"1. Caching"}}]}

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":24,"completion_tokens":180,"total_tokens":204,"prompt_cache_hit_tokens":0,"prompt_cache_miss_tokens":24}}

data: [DONE]

Responses

200The completion: a JSON object, or an SSE stream when stream is true.
application/jsontext/event-stream
  • X-Laras-Request-ID string — Billing identity of the request (UUID). Quote it when you contact support about a charge.
400The request is invalid.
application/json
CodeTypeMeaning
invalid_requestinvalid_request_errorThe body is not valid JSON or names no model.
max_tokens_exceededinvalid_request_errormax_tokens or max_completion_tokens is above 384,000.
unsupported_contentinvalid_request_errorA message contains an image or another non-text part.
401Authentication failed.
application/json
CodeTypeMeaning
invalid_api_keyinvalid_request_errorThe key is missing, malformed, revoked, or unknown.
402The wallet or the key budget cannot cover the request. Rejected before the model is called; nothing is held.
application/json
CodeTypeMeaning
insufficient_creditinsufficient_quotaAvailable balance is $0.00 or below. Top up.
key_budget_exceededinsufficient_quotaThe request would take the key past its monthly budget.
403The key lacks the chat:write scope.
application/json
CodeTypeMeaning
insufficient_scopeinsufficient_permissionsThe key cannot call this endpoint.
404The model is not served.
application/json
CodeTypeMeaning
model_not_foundinvalid_request_errorUse deepseek-flash.
413The request body is larger than 16 MB.
application/json
CodeTypeMeaning
request_too_largeinvalid_request_errorTrim the conversation or tool output.
429A per-key limit was hit. Wait for Retry-After.
application/json
  • Retry-After integer — Seconds to wait before retrying.
CodeTypeMeaning
rate_limit_exceededrate_limit_exceededMore than 300 requests in a minute on this key.
concurrency_limit_exceededrate_limit_exceededMore than 16 requests in flight on this key.
502The model provider failed or could not be reached.
application/json
CodeTypeMeaning
provider_unavailableapi_errorRetry with backoff.
503Billing is temporarily unavailable; the request was not run.
application/json
CodeTypeMeaning
billing_unavailableapi_errorRetry later. You were not charged.