Authentication methods
OpenGen supports three authentication transports, all strictly scoped to a single workspace:
| Method | Token or Cookie | Intended Caller | Lifecycle & Revocation |
|---|---|---|---|
| Workspace API key | Authorization: Bearer og_sk_<64-hex> | Server backends, CI jobs, scripts, non-OAuth agents | Created in /app/keys; supports explicit scopes, expiry, routing policy, and monthly spend cap; revocable anytime |
| OAuth 2.1 (DCR + S256 PKCE) | Authorization: Bearer og_mcp_a_<43-base64url> | Hosted assistants, coding agents, IDEs, @opengen-dev/cli | 1-hour access token TTL; 30-day grant with refresh-token rotation (og_mcp_r_...); revocable via POST /oauth/revoke or /app/apps |
| Browser session cookie | Cookie: og_session=<opaque> | OpenGen web console (/dashboard, /playground, /billing) | HttpOnly, SameSite=Lax, Secure on HTTPS, 12-hour TTL; signed in via Google OIDC, GitHub OAuth, or Email OTP |
Scoped workspace API keys
Create dedicated least-privilege keys in /app/keys. Send the key strictly in the Authorization header — never in query strings, request bodies, committed files, or CLI positional arguments.
# Verify authentication and inspect available/reserved workspace credit
curl --fail-with-body "$OPENGEN_API_URL/v1/balance" \
-H "Authorization: Bearer $OPENGEN_API_KEY"Each workspace API key can optionally bind:
- **Expiration (
expiresAt)**: expired keys immediately fail with401 unauthorized. - **Monthly spend cap (
monthlyCapMicros)**: hard integer micro-USD ceiling per key. - **Governance routing policy (
policyId)**: restricts allowed models, serving providers, endpoint regions, and per-requestmaxCostMicros. Request-levelroutingparameters can only narrow an attached policy, never broaden it.
Permission scopes
Every workspace credential carries an explicit set of scopes. Requests missing the required scope fail closed with 403 insufficient_scope.
| Scope | Public Developer Endpoints & MCP Tools | Notes |
|---|---|---|
| _(none — public)_ | GET /health, GET /openapi.json, GET /v1/models*, GET /v1/collections*, GET /v1/routes, GET /v1/pricing, POST /v1/pricing/estimate, GET /.well-known/webhook-jwks.json, and 4 public tools on /mcp/readonly | Unauthenticated catalog GETs are CDN-cached; authenticated calls switch to Cache-Control: no-store |
read | GET /v1/balance, GET /v1/analytics, GET /v1/generations, GET /v1/generations/lookup, GET /v1/generations/{id}, GET /v1/generations/{id}/status, GET /v1/generations/{id}/events, GET /v1/assets, and workspace read MCP tools (balance, analytics, job_get, jobs_list, assets_list) | Safe read-only visibility into workspace balance, jobs, outputs, assets, and analytics |
generate | POST /v1/generations, POST /v1/generations/{id}/cancel, DELETE /v1/generations/{id}/outputs, POST /v1/assets, POST /v1/assets/complete, DELETE /v1/assets, and /mcp write tools (generate, job_cancel, upload_asset, upload_attachment, delete_asset, purge_job_outputs) | Authorizes spending managed credit or BYOK runs and mutating/purging private media |
keys:write | Workspace API key administration (internal console surface) | Never delegated via MCP OAuth |
policies:write | Governance routing policy administration | Never delegated via MCP OAuth |
connections:write | Encrypted BYOK provider connection administration | Never delegated via MCP OAuth |
webhooks:write | Workspace alert configuration (GET/PUT /v1/alerts/settings, GET /v1/alerts) | Not required for per-request webhookUrl on POST /v1/generations |
members:write | Team membership and role administration | Admin only; never delegated via MCP OAuth |
feedback:write | Feedback and catalog request submission | Never delegated via MCP OAuth |
OAuth 2.1 with Dynamic Client Registration & PKCE
OpenGen implements OAuth 2.1 with Dynamic Client Registration (RFC 7591), S256 PKCE, Protected Resource Metadata (RFC 9728), and Resource Indicators (RFC 8707). OpenGen does not use Client ID Metadata Documents (CIMD).
Discovery and protocol endpoints
GET /.well-known/oauth-authorization-server— authorization server metadata (issuer,authorization_endpoint,token_endpoint,registration_endpoint,revocation_endpoint,code_challenge_methods_supported: ["S256"],token_endpoint_auth_methods_supported: ["none"]).GET /.well-known/oauth-protected-resourceandGET /.well-known/oauth-protected-resource/mcp— RFC 9728 metadata for full/mcp(scopes_supported: ["read", "generate"]).GET /.well-known/oauth-protected-resource/mcp/readonly— RFC 9728 metadata for/mcp/readonly(scopes_supported: ["read"]).POST /oauth/register— public client registration (1–10redirect URIs; supports public HTTPS callbacks, RFC 8252 literal HTTP loopbackhttp://127.0.0.1/http://[::1]with ephemeral positive ports, and exacthttp://localhost:<port>/callbacks).GET /oauth/authorize— browser authorization endpoint requiringresponse_type=codeandcode_challenge_method=S256.POST /oauth/token— exchangesauthorization_codeor rotatesrefresh_token(1hour access token TTL,30day grant lifetime).POST /oauth/revoke— revokes an access or refresh token (grants can also be revoked individually in/app/apps).
RFC 8707 audience isolation
OAuth tokens minted for /mcp (resource: "https://opengen.dev/mcp") and tokens minted for /mcp/readonly (resource: "https://opengen.dev/mcp/readonly") are strictly audience-isolated. Presenting a /mcp/readonly token to /mcp — or a /mcp token to /mcp/readonly — fails with 401 and a WWW-Authenticate challenge pointing to the matching resource_metadata URL.
Workspace isolation, CSRF, and caching boundaries
- Expected workspace guard: On
GET /v1/balance, callers can sendX-OpenGen-Expected-Workspace: <workspaceId>to ensure the credential still resolves to the intended paying workspace; mismatches return409 workspace_changed. - CSRF protection: Cookie-bearing (
og_session) cross-origin mutations are rejected with403 origin_denied. Cookie-free Bearer/public cross-originPOSTcalls on/mcp,/mcp/readonly, and/v1/pricing/estimateare permitted via public CORS (Access-Control-Allow-Origin: *, neverAccess-Control-Allow-Credentials: true). - Private caching: Every request carrying an
Authorizationheader orog_sessioncookie — and every private endpoint under/v1/generations*,/v1/assets*,/v1/balance,/v1/analytics,/mcp, and/mcp/readonly— is served withCache-Control: no-store.
Related pages
- MCP Server & Tools — connect
/mcpor zero-auth/mcp/readonly. - Agent Clients — client-specific OAuth setup for ChatGPT, Claude, Codex, Claude Code, Cursor, Grok Bot, Hermes Agent, Muse Code, and CLI.
- Errors & Recovery — handle
401 unauthorized,403 insufficient_scope, and403 policy_denied.