Guide
Monetize a Mac AI app
Native Mac apps whose AI runs on your users' plans, in Swift or Electron.
Updated November 2026
Why it suits Mac apps
A Mac app that calls AI either ships your API key (anyone can pull it out of the app) or needs a server to hide it, and then you pay for every user's AI. With Chabi, each user signs in with their own plan and the app calls AI with their token: no key in the app, no server, no AI bill. Users subscribe to Chabi on its website, not in your app.
Electron
Use the SDK's Node entry. It opens the system browser to sign in and listens on 127.0.0.1 for the return. Register http://127.0.0.1/callback as a redirect URI in the portal.
import { app, shell, safeStorage } from "electron";import { Chabi } from "@chabi/js/node";import OpenAI from "openai";const chabi = new Chabi({clientId: CHABI_CLIENT_ID,storage, // { load, save, clear }: encrypt the tokens with safeStorageopenBrowser: (url) => shell.openExternal(url),});await chabi.load();if (!chabi.signedIn) await chabi.signIn();const ai = new OpenAI(chabi.openai());
Swift
There's no Swift SDK yet, so sign in with OAuth 2.0 and PKCE by hand. There is no client secret. Register your app's URL scheme (for example myapp://callback) as the redirect URI.
- Make a random
code_verifierandstate, and the challenge: base64url of the verifier's SHA-256 (CryptoKit). - Open
https://chabi.dev/oauth/authorizewithresponse_type=code,client_id,redirect_uri,code_challenge,code_challenge_method=S256andstate, in anASWebAuthenticationSession. - When it returns, check
state, then POST form-encoded tohttps://chabi.dev/oauth/tokenwithgrant_type=authorization_code,code,redirect_uri,client_idandcode_verifier. - Keep the access and refresh tokens in the Keychain. Refresh before the access token expires; each refresh token works once, so always save the new one.
Then call AI as you would OpenAI's API, with Chabi's base URL and the user's token:
var req = URLRequest(url: URL(string: "https://chabi.dev/v1/chat/completions")!)req.httpMethod = "POST"req.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")req.setValue("application/json", forHTTPHeaderField: "Content-Type")req.httpBody = try JSONEncoder().encode(body) // { model, messages }let (data, response) = try await URLSession.shared.data(for: req)
The full flow, refresh rules and errors are in the sign-in docs.
What your users see
A Sign in with Chabi button, Chabi's sign-in in their browser, and one screen asking them to allow your app. After that, the app just works, and its AI comes out of their plan (Lite $5 a month (250 credits), Basic $10 a month (500 credits), Pro $20 a month (1,100 credits), Max $100 a month (6,000 credits)). Chabi Voice, a Mac dictation app, works this way.
Next
- Read the docs: sign-in, requests and errors, with copyable code.
- The AI prompt: paste it into Claude Code, Cursor or another coding agent, and it adds Sign in with Chabi to your app.
- Open the developer portal to register your app and get a client ID.
- Work out your AI bill and earnings with the calculator.