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

# Link Overview

> Use Link to connect to your users' AI subscriptions and API keys with Dari.

## Introduction To Link

Dari Link is the client-side component that your users interact with to connect their AI subscriptions and API keys to your app. Once a user connects, your app makes model requests on what they shared. You never see their credentials, and you don't pay for their usage.

An example Link flow. Your user's exact flow may differ.

**1. The user clicks Connect with Dari**

A small popup opens.

**2. Signs in with Dari**

With Google or an email link. On hosted Dari this is their Dari account, so anything they already connected there is ready to share.

**3. Picks what to connect**

A subscription (ChatGPT, Claude, OpenCode Go, Meta Muse) or an API key (OpenAI, Anthropic, OpenRouter, and more).

**4. Signs in to that provider**

The same sign-in they already know.

**5. And allows your app**

The popup closes. Your app is connected.

Link handles provider sign-in, choosing which plans and keys to share, consent, and the errors along the way. The next app that uses Link is one click for the same user: Dari remembers what they connected.

## Link Supported Platforms

| For... | Use... |
| - | - |
| A web app with a server | The [Link Web SDK](https://docs.dari.dev/link/web.md), with a **Server** app |
| A browser-only, desktop, or CLI app | The [Link Web SDK](https://docs.dari.dev/link/web.md) or the [authorize URL](https://docs.dari.dev/link/reference/http.md#authorize), with a **Browser Or Native** app |
| Users on your own infrastructure | The [self-hosted gateway](https://docs.dari.dev/link/run-a-gateway.md), which serves the same Link |

## Initializing Link

Link is opened with your app's `client_id`, which you get by registering your app. There is nothing to create on your server before opening it. For details, see the [Quickstart](https://docs.dari.dev/link/quickstart.md) and the [Link Web SDK](https://docs.dari.dev/link/web.md).

## Link Flow Overview

Link gives your app a temporary `code`, which your server exchanges for a permanent `refresh_token`.

**The Link flow** begins when your user wants to connect their AI subscription to your app.

```mermaid theme={null}
sequenceDiagram
  participant U as User
  participant A as Your app
  participant D as Dari
  participant P as OpenAI / Anthropic / …
  U->>A: Click Connect with Dari
  A->>D: Open Link
  U->>D: Connect a plan, click Allow
  D->>A: code
  A->>D: Exchange code for refresh_token
  A->>D: Model requests
  D->>P: Served on the user's plan
```

**Step 1**

Call [`DariLink.open`](https://docs.dari.dev/link/web#open) to open Link for your user. When they allow your app, Link provides a temporary `code`.

**Step 2**

Call [`/v1/link/token`](https://docs.dari.dev/link/reference/http#exchange-code) to exchange the `code` for a permanent `refresh_token` and `grant_id` for the new connection.

**Step 3**

Store the `refresh_token`. It is the only thing your app keeps for the connection.

**Step 4**

Use the `refresh_token` to make model requests on what your user connected.

In code, the flow has two halves:

* **On the frontend:** `DariLink.open` resolves with the `code` once the user allows your app.
* **On the backend:** your server sends the `code` to `/v1/link/token`, stores the `refresh_token` it gets back, and uses it for every later call.

## What Link Handles

Dari checks each of these on every request, so your app does not build them.

| Your app does not build | Because |
| - | - |
| Token storage beyond the one string, or a refresh lock | A server's refresh token never rotates. Any number of processes can use it at once |
| A check that a model is allowed | Dari refuses it with `424 model_not_granted`, and refuses to mint a [child token](https://docs.dari.dev/link/sandboxes.md) for it |
| Tracking plan limits or the user's budget | Dari refuses the request and says why. Show its message |
| Polling for a disconnect | The next call answers `401 grant_revoked`. Show **Reconnect** |
| Counting tokens out of responses | [`/v1/link/usage`](https://docs.dari.dev/link/usage-and-budgets) reads them back, by your own tags |
| Plan and usage screens | Link to the grant's `manage_url`, Dari's page for that connection |
| A fake Dari for tests | The [stub gateway](https://docs.dari.dev/link/test-your-integration.md) is a real one on stand-in plans |

## What Users Can Connect

Users connect ChatGPT, Claude, OpenCode Go, and Meta Muse subscriptions, and API keys for model providers and gateways. Some plans serve any app, and some only their vendor's own coding agent. To learn more, see [What Users Can Connect](https://docs.dari.dev/link/what-users-can-connect.md).

## Error-Handling Flows

Your user can change what they shared with your app without connecting again. This is called update mode. For more information, see [Manage Connections](https://docs.dari.dev/link/manage-connections.md#update-mode).

A user can disconnect your app from Dari at any time. Your next call for that connection answers `401 grant_revoked`, and your app should offer to connect again. For information on handling this flow, see [Manage Connections](https://docs.dari.dev/link/manage-connections.md#when-to-show-reconnect).

A `code` is single-use and expires 10 minutes after Link provides it. Exchange it as soon as your app receives it.

## Sandboxes And Workers

If your app runs agents in sandboxes, give each one a short-lived child token that serves only the models it needs, instead of your user's own token. To learn more, see [Sandboxes And Workers](https://docs.dari.dev/link/sandboxes.md).

## Usage And Budgets

Dari records what every request of a connection used, and your app reads it back by its own tags. Your user can also cap what your app may use. To learn more, see [Usage And Budgets](https://docs.dari.dev/link/usage-and-budgets.md).

## Testing

The stub gateway is the real gateway on stand-in plans, so your tests run the whole flow without a subscription or a paid call. To learn more, see [Test Your Integration](https://docs.dari.dev/link/test-your-integration.md).

## Hosted Or Self-Hosted

Point your app at hosted Dari (`https://routing.dari.dev`), or run the [self-hosted gateway](https://docs.dari.dev/link/run-a-gateway.md) for your own users. Both serve the same Link and the same rules. On hosted Dari, users sign in with their Dari account, and their plans are that account's. A self-hosted gateway has no accounts: a user's first plan makes their connection, and their browser remembers it.

Users see and manage what they connected at `/v1/link/connections` on the same host. Conversations are not stored. Dari keeps only routing data.


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