Skip to main content

Introduction

You’ll need API keys, which you get by registering your app in the console under Apps. Choose the app type Server, and add the redirect URI https://myapp.com/dari/callback. To try the flow without a real subscription, point the examples at the stub gateway.
With an organization’s API key, or on your own gateway. See Register App.
cURL

How It Works

Your app uses both a client-side component and a server to connect a user. The flow looks like this: The Link flow begins when your user wants to connect their AI subscription to your app.
1
Call DariLink.open to open Link for your user. When they allow your app, Link provides a temporary code.
2
Call /v1/link/token to exchange the code for a permanent refresh_token and grant_id for the new connection.
3
Store the refresh_token. It is the only thing your app keeps for the connection.
4
Use the refresh_token to make model requests on what your user connected.
The first step is to open Link. Link is a drop-in client-side module that handles the whole connection: signing in, picking plans and keys, and consent. It runs in the browser, so it is JavaScript whatever your server is written in. Once your user allows your app, DariLink.open resolves with a code and its codeVerifier, which your page sends to your server.
The JavaScript and React tabs use the client from npm (npm install @mupt-ai/dari-gateway). The HTML tab needs nothing installed. The page at your redirect URI runs one line, DariLink.callback(). See callback(). Next, on your server, call /v1/link/token to exchange the code for a refresh_token. The refresh_token uniquely identifies the connection and is a required argument for every later call. It never changes, and it is useless without your client_secret. Store it with your user in your own database.
Protect this endpoint from cross-site requests the way you protect any other that changes a user’s account.

Making API Requests

Now that your app has a refresh_token, it can make model requests on what the user connected. Dari’s endpoints speak the OpenAI and Anthropic protocols, so any client for those works. A request carries an access token, which one call makes from the refresh_token. It lasts an hour: the Node client makes and keeps it for you, and in other languages you keep it and reuse it until it expires.
Example response data:
/v1/chat/completions response

Next Steps

Congratulations, you have completed the Dari Link Quickstart! There are a few directions you can go in now: Choose which plans and keys Link offers your users. See What Users Can Connect. Let users change what they shared, and handle a user who disconnects. See Manage Connections. Running agents in sandboxes? Give each one its own short-lived token. See Sandboxes And Workers. Read back what a run or a user used. See Usage And Budgets. Test the whole flow without a real subscription. See Test Your Integration. For every option and endpoint, see the Link Web SDK and the Link endpoints reference.