Ointerference
DOCS
API Reference

Chat Completions API Reference

Specification for the authenticated POST /v1/chat/completions endpoint.

POST /v1/chat/completions (Authenticated Endpoint)

Generates chat completions from models, with full support for Server-Sent Events (SSE) streaming, autonomous tool calling, structured JSON output, and reasoning tokens.

Authenticated Access: This endpoint requires a valid API key with a non-zero credit balance passed via Authorization: Bearer sk_live_....


Request Headers

HeaderTypeRequiredDescription
AuthorizationstringYesBearer token format: Bearer sk_live_...
Content-TypestringYesMust be application/json

Request Body Parameters

{
  "model": "kimi-k2.7-code",
  "messages": [
    { "role": "system", "content": "You are an expert TypeScript engineer." },
    { "role": "user", "content": "Write a rate limiter using a sliding window algorithm." }
  ],
  "stream": true,
  "temperature": 0.7,
  "max_tokens": 1000,
  "tools": []
}

Parameters Reference

ParameterTypeRequiredDescription
modelstringYesModel identifier (e.g. kimi-k2.7-code, glm-5.3-flash, qwen3.6-plus, deepseek-v4-flash).
messagesarrayYesArray of conversation messages (role: system | user | assistant | tool, content: string).
streambooleanNoIf true, returns Server-Sent Events (SSE). Recommended for interactive apps and coding harnesses.
temperaturenumberNoSampling temperature between 0 and 2. Defaults to 1.
max_tokensintegerNoMaximum number of completion tokens to produce.
toolsarrayNoArray of OpenAI-format tool definitions for function calling.
tool_choicestring | objectNoControls tool selection: "none", "auto", "required", or specific function object.
response_formatobjectNoE.g. { "type": "json_object" } to force valid JSON output.
stopstring | arrayNoUp to 4 sequences where the model should stop generating.

Response Formats

1. Streaming Response (stream: true)

Returns a continuous text/event-stream stream formatted as Server-Sent Events (SSE):

data: {"id":"chatcmpl_9876","object":"chat.completion.chunk","created":1740000000,"model":"kimi-k2.7-code","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl_9876","object":"chat.completion.chunk","created":1740000000,"model":"kimi-k2.7-code","choices":[{"index":0,"delta":{"content":"Here"},"finish_reason":null}]}

data: {"id":"chatcmpl_9876","object":"chat.completion.chunk","created":1740000000,"model":"kimi-k2.7-code","choices":[{"index":0,"delta":{"content":" is"},"finish_reason":null}]}

data: [DONE]

2. Deep Reasoning Models (reasoning_content)

Reasoning models stream their internal thought processes in delta.reasoning_content before emitting the final answer in delta.content:

{
  "choices": [
    {
      "index": 0,
      "delta": {
        "reasoning_content": "Analyzing algorithmic complexity of sliding window..."
      }
    }
  ]
}

3. Non-Streaming Response (stream: false)

{
  "id": "chatcmpl_987654321",
  "object": "chat.completion",
  "created": 1740000000,
  "model": "kimi-k2.7-code",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "export class SlidingWindowRateLimiter { ... }"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 42,
    "completion_tokens": 128,
    "total_tokens": 170
  }
}

Two-Phase Atomic Credit Reservations

Interference uses atomic credit reservations to prevent runaway charges and negative balances:

  1. Pre-flight Hold: Before initiating inference, a temporary credit hold is placed based on prompt length and estimated max output.
  2. Stream Execution: Tokens are streamed with zero delay.
  3. Post-flight Settlement: Once the stream ends (or if the user cancels with Ctrl+C), the hold is settled for the exact number of tokens actually generated, and any unused credit hold is returned immediately to your balance.

On this page