Chat Completions

POST /v1/chat/completions

POST /v1/chat/completions speaks the OpenAI chat completions wire format. Authenticate with Authorization: Bearer sapi_.... For everything not called out below — message formats, tool calling, response shape — see OpenAI Compatibility; this page only covers what’s specific to SingularityAPI.

Request notes

  • model — required. A catalog slug (e.g. deepseek-v4-flash) or contract/{slug} for a contract. Must match exactly; see Models & Pricing for the catalog.
  • Output limit field — DeepSeek and Kimi models take max_tokens; gpt-5.6 models take max_completion_tokens. Sending the wrong field for the model is a 400. The value must be a positive integer, no larger than the model’s max output. Omit it and the per-model default is injected server-side — check the receipt’s transformed_fields to see when this happened.
  • stream — boolean. See Streaming for the SSE details.
  • Unsupported or reserved parameters are rejected with a 400, not silently dropped.

Example

$curl https://api.singularityapi.dev/v1/chat/completions \
> -H "Authorization: Bearer $SINGULARITY_API_KEY" \
> -H "Content-Type: application/json" \
> -d '{
> "model": "deepseek-v4-flash",
> "messages": [{"role": "user", "content": "Say hello."}]
> }'

A response looks like this:

1{
2 "id": "chatcmpl-abc123",
3 "object": "chat.completion",
4 "created": 1690000000,
5 "model": "deepseek-v4-flash",
6 "choices": [
7 {
8 "index": 0,
9 "message": {
10 "role": "assistant",
11 "content": "Hello! How can I help you today?"
12 },
13 "finish_reason": "stop"
14 }
15 ],
16 "usage": {
17 "prompt_tokens": 9,
18 "completion_tokens": 10,
19 "total_tokens": 19
20 }
21}

model in the response is the served model — the catalog model that actually ran the request. On a direct catalog call this matches what you sent; on a contract call it’s the contract’s current target.

Response headers

Every response carries:

  • x-singularity-request-id
  • x-singularity-receipt-id
  • x-singularity-contract-revision — present on contract calls only

Use the receipt ID to pull the exact cost and token usage from GET /v1/receipts/{id}.

Limits

  • A request may run up to ~230 seconds. Exceeding it returns 504 request_timeout.
  • Request bodies over the size cap are rejected with 413 request_too_large.

See Errors & Rate Limits for the full error envelope and status table.