> ## 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.

# Call Models

> Use the token like any OpenAI or Anthropic API key.

## From Your Server

```ts Node theme={null}
import { linkFetch } from "@mupt-ai/dari-gateway/link/client";

// refreshToken: the one you saved for this user.
const dari = linkFetch({
  gatewayUrl: DARI_GATEWAY_URL,
  clientId: CLIENT_ID,
  clientSecret: CLIENT_SECRET,
  refreshToken,
});

await dari("/v1/chat/completions", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ model: "gpt-5.5", messages: [{ role: "user", content: "Hi" }] }),
});
```

```python Python theme={null}
import requests

response = requests.post(f"{DARI_GATEWAY_URL}/v1/chat/completions",
    headers={"Authorization": f"Bearer {access_token}"},
    json={"model": "gpt-5.5", "messages": [{"role": "user", "content": "Hi"}]})
```

```go Go theme={null}
body := `{"model": "gpt-5.5", "messages": [{"role": "user", "content": "Hi"}]}`
req, _ := http.NewRequest("POST", dariGatewayURL+"/v1/chat/completions",
	strings.NewReader(body))
req.Header.Set("Authorization", "Bearer "+accessToken)
req.Header.Set("Content-Type", "application/json")
response, err := http.DefaultClient.Do(req)
```

```bash cURL theme={null}
curl $DARI_GATEWAY_URL/v1/chat/completions \
  -H "Authorization: Bearer $ACCESS_TOKEN" -H "content-type: application/json" \
  -d '{"model": "gpt-5.5", "messages": [{"role": "user", "content": "Hi"}]}'
```

`linkFetch` makes an access token from the refresh token, keeps it in memory, and replaces it when it expires. Safe to use from many servers at once, and cheap to make on every request. In the other tabs, one call makes the access token from the refresh token you saved, and it lasts an hour: see [Refresh](https://docs.dari.dev/link/reference/http.md#refresh).

## With An SDK

Point any OpenAI or Anthropic SDK at Dari, with an access token as the key:

```ts OpenAI (Node) theme={null}
import OpenAI from "openai";
import { refresh } from "@mupt-ai/dari-gateway/link/client";

const { accessToken } = await refresh({
  gatewayUrl: DARI_GATEWAY_URL,
  clientId: CLIENT_ID,
  clientSecret: CLIENT_SECRET,
  refreshToken,
});
const openai = new OpenAI({ baseURL: `${DARI_GATEWAY_URL}/v1`, apiKey: accessToken });
```

```python OpenAI (Python) theme={null}
from openai import OpenAI

openai = OpenAI(base_url=f"{DARI_GATEWAY_URL}/v1", api_key=access_token)
```

```ts Anthropic (Node) theme={null}
import Anthropic from "@anthropic-ai/sdk";
import { refresh } from "@mupt-ai/dari-gateway/link/client";

const { accessToken } = await refresh({
  gatewayUrl: DARI_GATEWAY_URL,
  clientId: CLIENT_ID,
  clientSecret: CLIENT_SECRET,
  refreshToken,
});
const anthropic = new Anthropic({ baseURL: DARI_GATEWAY_URL, apiKey: accessToken });
```

```python Anthropic (Python) theme={null}
from anthropic import Anthropic

anthropic = Anthropic(base_url=DARI_GATEWAY_URL, api_key=access_token)
```

An access token lasts an hour. For longer work, or a process outside your server such as a sandbox, mint a [child token](https://docs.dari.dev/link/sandboxes.md) and use it as the key.

## Apps Without A Server

A public client (a browser-only, desktop, or CLI app) has no secret, so its refresh token rotates: each refresh returns a new one, and the old one stops working. Save every reply before you use it.

```ts Node theme={null}
import { readFile, writeFile } from "node:fs/promises";
import { linkFetch } from "@mupt-ai/dari-gateway/link/client";

// Instead of refreshToken, give the client somewhere to keep the tokens.
const dari = linkFetch({
  gatewayUrl: DARI_GATEWAY_URL,
  clientId: CLIENT_ID,
  loadTokens: async () => JSON.parse(await readFile("tokens.json", "utf8")),
  saveTokens: (tokens) => writeFile("tokens.json", JSON.stringify(tokens)),
});
```

```python Python theme={null}
import requests

# No client secret: send client_id in the form instead.
reply = requests.post(f"{DARI_GATEWAY_URL}/v1/link/token", data={
    "grant_type": "refresh_token",
    "client_id": CLIENT_ID,
    "refresh_token": refresh_token,
})
reply.raise_for_status()
tokens = reply.json()
# Save tokens["refresh_token"] before you use tokens["access_token"]:
# it is new each time.
```

```bash cURL theme={null}
# No client secret: send client_id in the form instead.
curl -X POST $DARI_GATEWAY_URL/v1/link/token \
  -d grant_type=refresh_token -d client_id=$CLIENT_ID -d refresh_token=$REFRESH_TOKEN
# Save refresh_token from the reply: it is new each time.
```

Save what [`exchange`](https://docs.dari.dev/link/reference/http#exchange-code) returns the same way when the user connects. With the Node client, `childToken`, `grant`, and `usage` take the same two functions.

## Endpoints

| Endpoint | Protocol |
| - | - |
| `POST /v1/chat/completions` | OpenAI Chat Completions |
| `POST /v1/responses` | OpenAI Responses |
| `POST /v1/messages` | Anthropic Messages |
| `GET /v1/models` | Models this user's connection can serve now |

## Model Names

| You send | You get |
| - | - |
| `dari/routing` | Dari picks the best model the user's plans can serve |
| `gpt-5.5`, `claude-sonnet-5-5` | Exactly that model |
| `dari/model/openai/gpt-5.5` | Same, fully named |
| `openrouter/<id>`, `vercel-ai-gateway/<id>` | Any model on a connected OpenRouter or Vercel key |

Ask for a model the user's plans can't serve and you get `424 model_not_granted`. Check `GET /v1/models` first.

## Response Headers

| Header | Value |
| - | - |
| `X-Dari-Selected-Model` | The model that answered |
| `X-Dari-Usage` | Token counts (non-streamed) |
| `X-Request-Id` | Look up this request's usage later |


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