Sign-in to your service

AI Studio stores the user's key or token on their computer, renews it, and hands it to your MCP server and your panel's requests. Your code never stores credentials.

auth.typeThe userYou provide
noneNothing.Nothing.
api-keyPastes a key in the Plugins tab.label, helpUrl (where to find the key).
oauthSigns in in the browser.authorizeUrl, tokenUrl, clientId, scopes.
mcp-oauthSigns in in the browser.An MCP server that implements MCP authorization.

API key

"auth": { "type": "api-key", "label": "Acme API key", "helpUrl": "https://acme.example/settings/keys" }

OAuth

"auth": {
  "type": "oauth",
  "authorizeUrl": "https://acme.example/oauth/authorize",
  "tokenUrl": "https://acme.example/oauth/token",
  "clientId": "aistudio",
  "scopes": ["tickets:read", "tickets:write"]
}

Authorization code with PKCE (S256), as a public client: no secret. The redirect is a loopback address, http://127.0.0.1:<port>/api/plugins/callback, and the port varies, so your server must accept loopback redirects for this client (127.0.0.1 with any port, as RFC 8252 describes). Refresh tokens are used when present.

MCP authorization

"mcp": { "url": "https://mcp.acme.example/mcp" },
"auth": { "type": "mcp-oauth" }

AI Studio follows the MCP spec: the server's 401 with resource_metadata (or /.well-known/oauth-protected-resource), the authorization server's metadata, then dynamic client registration once per install. Use this when your MCP server already supports Claude's connectors: nothing else to configure.

Where the token goes

  • Hosted MCP server: Authorization: Bearer <token> on every request.
  • Local MCP server: the environment variable named by mcp.tokenEnv.
  • Panel: never directly. Use aistudio.fetch (below).

Calling your API from the panel

"auth": { "type": "oauth", "...": "...", "relay": ["https://api.acme.example"] }
const r = await aistudio.fetch('https://api.acme.example/v1/tickets?mine=1');
const tickets = await r.json();

aistudio.fetch takes the usual init (method, headers, body) and returns a Response. AI Studio sends the request with the token added, but only to the https origins listed in auth.relay. The panel's page never sees the token.

Sign-in state in the panel

const { connected } = await aistudio.ready();
if (!connected) showConnectButton(() => aistudio.connect());
aistudio.on('connection', ({ connected }) => connected ? load() : showConnectButton());

aistudio.auth.renew(params) refreshes the token with extra fields your token endpoint understands (switching workspace with { org_id }, for example). The grant's own fields (grant_type, refresh_token, client_id, scope and so on) cannot be set.