Chat completions

POST /v1/chat/completions — OpenAI-compatible. Both streaming and non-streaming, tool-calling, vision (where the model supports it), JSON mode.

Request

POST /v1/chat/completions
Authorization: Bearer im_live_...
Content-Type: application/json
Idempotency-Key: <optional, [A-Za-z0-9_\-.]{1,128}>

{
  "model": "im/anthropic-claude-3-5-sonnet",
  "messages": [
    { "role": "system", "content": "You are helpful." },
    { "role": "user",   "content": "Say hi" }
  ],
  "temperature": 0.7,
  "max_tokens": 512,
  "stream": false
}

Response

Identical shape to OpenAI's. Key fields:

  • choices[i].message.content — the model's reply.
  • usage.prompt_tokens / completion_tokens / total_tokens — used to compute the charge.

Streaming

Set stream: true. The response is text/event-stream SSE. Each chunk is an OpenAI-style chat.completion.chunk with a delta.content string. Final chunk has data: [DONE].

We honour client disconnects: if you abort mid-stream we still charge for the tokens already generated.

Headers we set

  • x-infra-request-id — the request UUID. Quote this when reporting issues; it joins your request to our logs and traces.

Idempotency-Key

Include the header to deduplicate retries. If two requests use the same key within 24h, the second won't re-charge your wallet. See /docs/idempotency.

Errors

All errors share the OpenAI envelope { error: { code, message, type, request_id } }. See /docs/errors for the full table.