GatewayPOST /v1/chat/completions

POST /v1/chat/completions

OpenAI-compatible chat completion endpoint. Supports streaming, tool use, and all standard parameters, plus gateway-specific extensions via providerOptions.gateway.

Request

POST https://router.tangle.tools/v1/chat/completions
Authorization: Bearer sk-tan-YOUR_KEY
Content-Type: application/json

Body

{
  "model": "anthropic/claude-sonnet-4-6",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello"}
  ],
  "temperature": 0.7,
  "max_tokens": 4096,
  "stream": true,
  "tools": [...],
  "tool_choice": "auto",
  "response_format": {"type": "json_object"},
  "top_p": 0.9,
  "frequency_penalty": 0,
  "presence_penalty": 0,
  "stop": ["\n\n"],
  "providerOptions": {
    "gateway": {
      "byok": {"anthropic": [{"apiKey": "sk-ant-..."}]},
      "zeroDataRetention": true,
      "caching": "auto",
      "models": ["openai/gpt-4o"],
      "timeout": 5000
    }
  }
}

All standard OpenAI parameters (tools, tool_choice, response_format, top_p, frequency_penalty, presence_penalty, stop, logprobs) are forwarded to the provider.

Routing headers (optional)

HeaderEffect
X-Tangle-Routingoperator, provider, or auto (default)
X-Tangle-BlueprintPin to operators under this Blueprint ID
X-Tangle-ServicePin to a specific service instance
X-Tangle-OperatorPin to a specific operator (slug or 0x address)
X-Payment-SignatureSpendAuth JSON payload for on-chain payment

Validation

FieldConstraint
modelRequired. Alphanumeric + /-.:\\_, max 128 chars.
messagesRequired. Non-empty array. Each must have role.
max_tokensOptional. 1-128,000. Default: 4,096.
temperatureOptional. 0-2. Default: 1.
Body sizeMax 1MB.

Response (non-streaming)

Standard OpenAI chat completion response:

{
  "id": "chatcmpl-...",
  "choices": [{
    "message": {"role": "assistant", "content": "Hello! How can I help?"},
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 15,
    "completion_tokens": 8,
    "total_tokens": 23
  }
}

Response (streaming)

Server-sent events with data: {...} lines and data: [DONE] terminator.

Response headers

See Response Headers for the full list.