Skip to content

Latest commit

 

History

History
55 lines (35 loc) · 3.07 KB

auth.md

File metadata and controls

55 lines (35 loc) · 3.07 KB

Authentication & Session Management

API Key Authentication

External HTTP requests to POST /v1/chat/completions can be authenticated with a Bearer token generated in the API Keys tab or via POST /v1/keys.

Provide the key in one of the following headers:

Authorization: Bearer <api_key>

or

X-Api-Key: <api_key>

Managing API Keys

Method Endpoint Description
GET /v1/keys List all API keys (masked)
POST /v1/keys Create a new API key ({"name": "cursor-local"})
POST /v1/keys/revoke Deactivate an API key ({"api_key": "..."})
DELETE /v1/keys/{key} Delete an API key

In debug/development builds, API key enforcement is bypassed by default so local testing works out of the box.


Session Management (X-Session-Id)

Send X-Session-Id on POST /v1/chat/completions to continue a conversation. The gateway reads, writes and serializes sessions by API key and session ID. Two keys can use the same ID with independent histories. A successful response returns the resolved x-session-id.

SQLite migrates existing session histories under their stored key hash. It retains ownerless rows without assigning them to an API caller.

Profile selection and cooldown

New sessions select from eligible profiles in round-robin order. A session keeps its profile while that profile is eligible. The gateway permits up to four upstream chat attempts per request, including session recovery and output corrections.

Upstream result Gateway behavior
DeepSeek 40003 / INVALID_TOKEN Cool down the affected profile. A different eligible profile can handle the request before streaming output starts.
HTTP 429 with unknown scope Cool down the provider across profiles and return HTTP 429 before streaming output starts.
403 without a specific rate-limit or expired-credential signal Return HTTP 403 without an automatic retry.
401 or confirmed expired credentials Mark the profile as requiring updated credentials. Updating the token or cookie clears that state.

The gateway honors the upstream Retry-After header. Without a header, it applies exponential backoff with jitter. When every eligible profile is rate limited, it returns HTTP 429 with Retry-After and leaves upstream untouched during cooldown. Cooldown state lives in the running gateway.

Recovering a conversation

When upstream rejects a session or parent message ID, the gateway can create a new upstream session on the same profile and rebuild the prompt from the saved history. Switching profiles or changing credentials also clears the old upstream IDs. The client session ID and completed history carry forward.

Before emitting content or reasoning, the gateway can recover from an eligible upstream failure. Structured JSON and tool output corrections follow the same attempt budget. After emitting content or reasoning, the gateway sends an SSE error if the attempt fails. It keeps the completed transcript and discards the failed turn, so a retry does not duplicate that user message.