Skip to main content
Integrating BrainLink in your app allows your users to connect their brains with a single click. This allows you to get rid of the inference costs and provides your app with a simple way to monetize without paywalls or sign-up forms. By integrating BrainLink your app is automatically listed in the BraiLink AI store, which is a powerful distribution channel and source of users. We are devs building for fellow devs.
If you are using React based frameworks like Next.js, you can directly import the BrainLink button:
import * as BrainLink from "@brainlink/spa-sdk";
import BrainLinkButton from "@brainlink/react-button";
...
// Use the button on your app
<BrainLinkButton appClientId="your-brainlink-app-client-id" />
...
// Get the user access token to run inference (see next section)
const userAccessToken = await BrainLink.getUserToken();
To see complete examples for different frameworks see our examples repository.
You can also import the BrainLink SDK script directly:
<script type="module" src="https://unpkg.com/@brainlink/spa-sdk/dist/index.js" crossOrigin="anonymous" />
Then, create a button and set as the on-click attribute the BrainLink.startCodeExchange(appClientId, appCallbackUrl); method. The application client ID must be the one you generated in the previous step and the callback URL is optional. You just need to provide a callback URL if you want the user to be redirected to a different page after connecting his BrainLink account, otherwise, it will remain on the same page.
And that’s all! Now your users will pay for the inference they consume by connecting their BrainLink account with your application in one click, so you don’t have to request them API keys.

Running inference

BrainLink’s API is fully OpenAI compatible, so you can directly use the OpenAI SDK or any other compatible one, just change the baseURL to https://www.brainlink.dev/api/v1. For example:
if (BrainLink.isConnected()) {
    const userAccessToken = await BrainLink.getUserToken();
    const openai = new OpenAI({
        baseURL: "https://www.brainlink.dev/api/v1",
        apiKey: userAccessToken,
        // Required to use the OpenAI SDK in the browser.
        // Since your app is securely using the user's access token via BrainLink, it's totally safe to use the SDK on the browser.
        dangerouslyAllowBrowser: true,
    });
}

const completion = await openai?.chat.completions.create({
    model: "google/gemini-2.0-flash-lite-preview-02-05:free",
    messages: messages,
});

Shortcuts