What
Enhance the existing API key authentication system with fine-grained scopes and model/provider restrictions. API keys should be able to restrict which models, providers, and operations a client can access.
Why
Rook's current API key system is binary — a key grants full access or no access. A production proxy needs:
- Scopes: Limit keys to specific operations (e.g.,
chat:write, chat:read, providers:read)
- Model restrictions: Allow keys to only use specific models
- Provider restrictions: Allow keys to only route to specific providers
- Read-only keys: For monitoring tools that should not make requests
Basic Spec
API Key with Restrictions
ApiKey {
id: string
name: string
key_hash: string // HMAC-SHA256 of the actual key
scopes: Vec<Scope>
allowed_models: Vec<ModelId> // empty = all allowed
allowed_providers: Vec<ProviderId> // empty = all allowed
rate_limit: Option<RateLimitRule>
is_active: bool
created_at: DateTime
expires_at: Option<DateTime>
last_used_at: Option<DateTime>
}
Scope = ChatRead | ChatWrite | ProvidersRead | ProvidersWrite | Admin
Enforcement
- Auth middleware validates key and extracts restrictions
- Request middleware checks scope before routing
- Model restriction checked against
CompletionRequest.model
- Provider restriction checked against selected provider
- Violations return HTTP 403 Forbidden
API
POST /api/api-keys — create key with restrictions
GET /api/api-keys — list keys (without showing the actual key)
PUT /api/api-keys/:id — update restrictions
DELETE /api/api-keys/:id — revoke key
POST /api/api-keys/:id/rotate — rotate key while keeping restrictions
User Stories
As a system operator
I want to create read-only API keys for monitoring tools
So that monitoring tools can check health without making requests
As a SaaS operator
I want to give each customer their own API key with model restrictions
So that customers cannot access models they haven't paid for
As a developer
I want to know exactly what a key can and cannot do
So that I can debug auth issues quickly
Acceptance Criteria
What
Enhance the existing API key authentication system with fine-grained scopes and model/provider restrictions. API keys should be able to restrict which models, providers, and operations a client can access.
Why
Rook's current API key system is binary — a key grants full access or no access. A production proxy needs:
chat:write,chat:read,providers:read)Basic Spec
API Key with Restrictions
Enforcement
CompletionRequest.modelAPI
POST /api/api-keys— create key with restrictionsGET /api/api-keys— list keys (without showing the actual key)PUT /api/api-keys/:id— update restrictionsDELETE /api/api-keys/:id— revoke keyPOST /api/api-keys/:id/rotate— rotate key while keeping restrictionsUser Stories
As a system operator
I want to create read-only API keys for monitoring tools
So that monitoring tools can check health without making requests
As a SaaS operator
I want to give each customer their own API key with model restrictions
So that customers cannot access models they haven't paid for
As a developer
I want to know exactly what a key can and cannot do
So that I can debug auth issues quickly
Acceptance Criteria
chat:read,chat:write,providers:read,providers:write,adminallowed_modelslist (empty = all models)allowed_providerslist (empty = all providers)GET /api/api-keysreturns keys without exposing the actual key material