> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dari.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat Completions API

> Send OpenAI-compatible Chat Completions requests through a router.

```bash theme={null}
curl "https://routing.dari.dev/v1/chat/completions" \
  -H "Authorization: Bearer $DARI_ROUTING_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dari/routing",
    "messages": [{"role": "user", "content": "Hello from Dari"}]
  }'
```

Use `/v1` for your default router. For a specific router, send the same body to `https://routing.dari.dev/{router_id}/chat/completions`.

The response follows the OpenAI Chat Completions format and adds `dari_routing`, which identifies the selected model and reasoning effort.

## Streaming

Set `stream: true`. Dari returns Server-Sent Events in the OpenAI stream format, with `dari_routing` in the first event and `data: [DONE]` at the end.

## Tool Calls

Send standard OpenAI `tools` and `tool_choice` fields. If the selected model calls a tool, append the result as a `tool` message and send the complete message history again.

## Conversations and Leases

The router groups requests into conversations. It remembers which model served earlier turns, and a routing policy can keep later turns on that model for a few turns (a lease). Send the same identity on every turn of one conversation, using either:

* the `x-session-affinity` header, or
* the `prompt_cache_key` body field.

If you send both, the header wins. Use a unique value for each run or session. Two runs that send the same value share one conversation, so one run can inherit the other's routing state.

If you send neither, the router matches the request's message history against earlier requests. Identical runs, such as retries of the same task, can then match each other, and the most recently active run wins. Rewriting earlier messages starts a new conversation.

The conversation is keyed on the system and tools head plus the message prefix, so compaction that keeps the earlier messages intact stays in the same conversation. Lease position is counted from the assistant messages in each request, so removing assistant turns moves when the next routing decision happens.

```bash theme={null}
curl "https://routing.dari.dev/v1/chat/completions" \
  -H "Authorization: Bearer $DARI_ROUTING_API_KEY" \
  -H "x-session-affinity: run-42" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dari/routing",
    "messages": [{"role": "user", "content": "Fix the failing test"}]
  }'
```

See the [Chat Completions API Reference](https://docs.dari.dev/api-reference/router/chat-completions.md) for supported fields.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.