Installation
Import Link
CSP Directives
If you are using a Content Security Policy (CSP), use the following directives to allow Link traffic:CSP Directives
connect-src is your gateway’s origin, which Link asks where to expect the result from. script-src is needed only for the script tag.
open()
DariLink.open accepts one argument, a configuration Object, opens Link in a popup, and returns a Promise. The promise resolves with a code once your user allows your app, and rejects with a LinkError when they leave without allowing it.
Call open straight from a click handler, so the browser allows the popup. If the configuration comes from your server, pass a function that returns it (DariLink.open(async () => ({ ... }))): Link opens the popup first and then awaits it.
Properties
The environment to connect on:
https://routing.dari.dev for hosted Dari, or your own gateway’s URL.One of your app’s registered redirect URIs. Link returns to it when the popup cannot reach your window. Its page must call
callback().The kinds of plan to offer. By default Link offers every kind your app can use.Possible values:
openai_codex, anthropic_claude_code, github_copilot, xai_grok, opencode_go, meta_muse, vercel_token_pass, api_keyThe providers whose API keys your app can use, such as
["openai", "openrouter"]. By default Link offers every one. See What Users Can Connect.The coding agents your app runs itself. A Claude plan serves only Claude Code, and a Meta Muse plan only Muse Code, so Link offers those plans only to an app that names the agent.Possible values:
claude_code, codex, muse_code, opencode, pi, openclaw, hermesThe
grant_id of an existing connection. Opens Link in update mode, where the user changes what that connection shares.A function that is called when your user reaches a step in Link. See onEvent.
A function that is called when your user leaves Link without allowing your app. See onExit.
A PKCE challenge made on your server, with
state. See Server-Made PKCE.A temporary code for the new connection. Send it to your server, which exchanges it at
/v1/link/token. It is single-use and expires in 10 minutes.The PKCE verifier that redeems
code. Send it to your server with the code. null when your server made the pair.Result schema
onEvent
TheonEvent callback is called when your user reaches a step in Link. It takes one argument, a step string. Use it to see where users drop off.
Properties
The step the user just reached.
connect_subscription: The user has nothing to share yet and is connecting a plan or key.choose_plans: The user is choosing which plans and keys your app may use.JavaScript
onExit
TheonExit callback is called when your user leaves Link without allowing your app, just before open rejects. It takes one argument, an Object with the error and the last step. open rejects with a LinkError whose code is the same error.
Properties
Why Link ended.
access_denied: The user chose Deny.popup_closed: The user closed the popup.popup_blocked: The browser blocked the popup. Call open straight from a click.insecure_context: The page is not https or localhost, so it cannot make its PKCE pair. See Server-Made PKCE.The last step the user reached:
connect_subscription or choose_plans. denied when the user chose Deny, and null when they reached no step.JavaScript
Exit schema
callback()
DariLink.callback hands a result that arrived on your redirect URI back to the window that called open, then closes the popup. A popup that signed your user in along the way can lose its link to your window, and Link then returns to your redirect URI instead. Call callback on that page.
callback returns false when the page holds no Link result.
renderButton()
DariLink.renderButton draws the standard Connect with Dari button into an element. It takes the element and a configuration Object.
Properties
The button’s text. Keep “Connect with Dari”, or “Reconnect Dari” for a connection that is gone.Default:
Connect with DariJavaScript
Server-Made PKCE
open makes its PKCE pair in the page, which needs https or localhost. If your page is neither, or you want the verifier never to reach the browser, make the pair on your server and pass codeChallenge and state to open.
open then resolves with a null codeVerifier. Check the returned state against the session, and exchange the code with the verifier you kept.