Docs/Sign in with Utopixel
Billing and account

Sign in with Utopixel

Let users sign in with their own Utopixel account and give your app a key that spends their balance. OAuth with PKCE, compatible with OpenRouter's flow.

Let your users bring their own Utopixel account: they approve your app once, you get an API key that spends their balance, and you never handle their billing. The flow is OAuth with PKCE and follows OpenRouter's, so code written for OpenRouter's flow works by changing the domain.

  1. Send the user to https://utopixel.online/auth with callback_url, code_challenge (base64url SHA-256 of your code_verifier) and code_challenge_method=S256.
  2. The user signs in, picks a workspace, can set a spending limit and expiry, and approves. We redirect to your callback_url with code (and your state). On deny we redirect with error=access_denied.
  3. Exchange the code within 10 minutes: POST /api/v1/auth/keys with code, code_verifier and code_challenge_method. The response JSON has a key field holding the new sk-vb-... key. Each code works once. The endpoint allows browser requests (CORS).
app.tstypescript
1// 1. PKCE: keep the verifier in the user's session, never in a URL
2 const verifier = base64url(crypto.getRandomValues(new Uint8Array(32)));
3 const challenge = base64url(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier))));
4 location.href = `https://utopixel.online/auth?callback_url=${encodeURIComponent("https://yourapp.com/callback")}` +
5 `&code_challenge=${challenge}&code_challenge_method=S256&key_label=Your%20App&limit=10`;
6
7 // 2. On /callback: exchange the one-time code for a key
8 const res = await fetch("https://utopixel.online/api/v1/auth/keys", {
9 method: "POST",
10 headers: { "Content-Type": "application/json" },
11 body: JSON.stringify({ code, code_verifier: verifier, code_challenge_method: "S256" }),
12 });
13 const { key } = await res.json(); // sk-vb-..., spends the user's balance

Optional parameters: key_label (key name), limit (USD, up to two decimals), expiration (1-hour, 1-day, 7-days, 30-days, 90-days, 180-days, 1-year, never), state, workspace_id and required_workspace_id. The user can change the label, limit and expiry before approving. callback_url must be https, or http on localhost. Headless mode (no callback) is not supported.

Errors: 400 when code_challenge_method is not S256, 403 for an invalid code or verifier, 403 for an expired code. Users see the key, marked with your app's host, on their API keys page and can revoke it any time.