| Internet-Draft | OAuth AI Scopes | December 2024 |
| HM | Expires 27 June 2025 | [Page] |
This document defines an extension to OAuth 2.0 for delegating scoped access to AI model APIs. It introduces a standardized scope syntax, resource indicators for AI providers, and token constraints suitable for AI workloads including spend limits and model restrictions.¶
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.¶
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.¶
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."¶
This Internet-Draft will expire on 27 June 2025.¶
Copyright (c) 2024 IETF Trust and the persons identified as the document authors. All rights reserved.¶
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Revised BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Revised BSD License.¶
The proliferation of AI model APIs (OpenAI, Anthropic, Google, Mistral, etc.) has created a need for secure delegation of API access. Current approaches involve sharing API keys directly with applications, which:¶
This specification extends OAuth 2.0 to address these concerns by defining:¶
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119].¶
AI-specific scopes follow this syntax:¶
ai:<provider>:<model>:<capability>¶
Examples:¶
| Provider | Identifier |
|---|---|
| OpenAI | openai |
| Anthropic | anthropic |
| Google AI | |
| Mistral | mistral |
| Groq | groq |
| Together AI | together |
| Cohere | cohere |
| Capability | Description |
|---|---|
| chat | Chat/text completions |
| embeddings | Vector embeddings |
| images | Image generation |
| audio | Audio transcription/synthesis |
| vision | Multimodal/vision |
| code | Code generation |
The token introspection response ([RFC7662]) is extended with:¶
{
"active": true,
"scope": "ai:openai:gpt-4:chat",
"ai_limits": {
"monthly_spend_usd": 100.00,
"daily_spend_usd": 10.00,
"requests_per_minute": 60,
"requests_per_day": 1000,
"max_tokens_per_request": 4096
},
"ai_usage": {
"spend_this_month_usd": 23.45,
"spend_today_usd": 2.10,
"requests_this_minute": 3,
"requests_today": 156
}
}
¶
| Field | Type | Description |
|---|---|---|
| monthly_spend_usd | number | Maximum spend per calendar month |
| daily_spend_usd | number | Maximum spend per day |
| requests_per_minute | integer | Rate limit (RPM) |
| requests_per_day | integer | Daily request limit |
| max_tokens_per_request | integer | Per-request token limit |
| Parameter | Type | Description |
|---|---|---|
| ai_limits | JSON | Requested limits (as defined in Section 3.2) |
| ai_reason | string | Human-readable reason for access |
Example authorization request:¶
GET /authorize?
response_type=code&
client_id=app123&
scope=ai:openai:gpt-4:chat&
ai_limits={"monthly_spend_usd":50}&
ai_reason=Code+assistant+for+IDE
¶
The resource server (authorization server or dedicated proxy) MUST:¶
When limits are exceeded:¶
{
"error": "ai_limit_exceeded",
"error_description": "Daily spend limit of $10.00 exceeded",
"ai_usage": {
"spend_today_usd": 10.23,
"daily_spend_usd": 10.00
}
}
¶
For high-security deployments, tokens SHOULD be sender-constrained using:¶
Resource servers:¶
This specification registers the "ai" scope prefix in the OAuth Parameters registry.¶
This specification requests the establishment of a registry for AI provider identifiers.¶
+--------+ +---------------+
| |--(1) Authorization Request--->| |
| | scope=ai:openai:gpt-4:chat| |
| | ai_limits={...} | Authorization |
| | | Server |
| |<-(2) Authorization Code-------| |
| | +---------------+
| |
| Client | +---------------+
| |--(3) Token Request----------->| |
| | | Token |
| |<-(4) Access Token-------------| Endpoint |
| | + ai_limits metadata | |
| | +---------------+
| |
| | +---------------+
| |--(5) API Request------------->| |
| | Authorization: Bearer ... | Resource |
| | POST /v1/chat/completions | Server |
| | | (Proxy) |
| |<-(6) API Response-------------| |
| | +---------------+
+--------+
¶
The author would like to thank the OAuth Working Group for their foundational work on authorization frameworks.¶