OpenRouter is API-token based. No browser cookies.
Data sources + fallback order
-
Credits API (primary)
GET https://openrouter.ai/api/v1/credits- Returns total credits purchased, total usage, and remaining balance.
- Used to compute a usage percentage and a credits snapshot.
-
Key info API (best-effort, parallel)
GET https://openrouter.ai/api/v1/auth/key- Returns key metadata: label, free-tier flag, rate-limit details.
- Runs in parallel with the credits call; failures are silently ignored.
- Populates
ProviderIdentitySnapshotwith tier/label/rate-limit info.
Credentials
Keychain
- Service:
com.sriinnu.athena.Runic.provider-credentials.v2 - Account:
openrouter-api-token
Environment variable
OPENROUTER_API_KEY
Fallback order: Keychain first, then environment.
Token store
Sources/Runic/Core/Stores/OpenRouterTokenStore.swift— reads/writes/deletes the Keychain item withkSecAttrAccessibleAfterFirstUnlock, supports migration from the Data Protection keychain.
API endpoints
GET https://openrouter.ai/api/v1/credits
- Headers:
Authorization: Bearer <api_key>Content-Type: application/json
- Timeout: 15 seconds
GET https://openrouter.ai/api/v1/auth/key
- Headers:
Authorization: Bearer <api_key>Content-Type: application/json
- Timeout: 15 seconds
- Best-effort: errors are logged and the response is treated as
nil.
Parsing + mapping
Credits response (OpenRouterCreditsResponse)
data.total_credits(ordata.credits, or top-levelcredits) -> total credits purchased.data.total_usage-> total credits consumed.remaining = max(0, totalCredits - totalUsage).usedPercent = (totalUsage / totalCredits) * 100, clamped 0-100.
Key-info response (OpenRouterKeyInfoResponse)
data.label-> key label.data.is_free_tier-> “Free tier” tag if true.data.rate_limit.requests+data.rate_limit.interval-> “N req/interval” string.- These are joined into
ProviderIdentitySnapshot.loginMethod.
Snapshot mapping (toUsageSnapshot)
- Primary:
RateWindowwithusedPercentfrom credits,windowMinutes: nil,resetsAt: nil,resetDescriptionshowing balance + spent amounts. - Secondary:
nil. - Tertiary:
nil. - Identity: provider ID
.openrouterwith login method string from key info. - Also produces a
CreditsSnapshotwithremainingbalance.
Key files
Sources/RunicCore/Providers/OpenRouter/OpenRouterProviderDescriptor.swiftSources/RunicCore/Providers/OpenRouter/OpenRouterUsageFetcher.swiftSources/Runic/Core/Stores/OpenRouterTokenStore.swift
Read the source ↗ Checked against Runic 2.13.5 · 9730f91