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 URIhttps://myapp.com/dari/callback.
To try the flow without a real subscription, point the examples at the stub gateway.
Register with the API instead
Register with the API instead
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.DariLink.open resolves with a code and its codeVerifier, which your page sends to your server.
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.
Making API Requests
Now that your app has arefresh_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.
/v1/chat/completions response