ai_anthropic_provider_oauth
Overview
Enables Anthropic Claude AI models in Drupal using long-lived OAuth setup tokens from your Claude subscription (Pro/Max/Team). This is an alternative to the standard API key authentication, designed for developers with existing Claude subscriptions who want to use their subscription benefits instead of separate API billing.
⚠️ Terms of Service Notice
Important: OAuth setup tokens from claude setup-token are officially intended for Claude Code CLI use. Using these tokens in third-party applications may violate Anthropic's Terms of Service.
For production use, please install AI Provider Anthropic and use official API keys from the Anthropic Console.
Appropriate use cases: Personal development, testing, internal tools, proof-of-concept projects.
Key Features
- Bearer Authentication: Uses
Authorization: Bearerwith OAuth setup tokens - Long-lived Tokens: Tokens valid for ~1 year, no automatic refresh needed
- Dynamic Model Discovery: Fetches available models from Anthropic API automatically
- Secure Storage: Integrates with Key module for credential management
- Automatic Token Validation: Tests tokens against live API on configuration
- Full AI Module Integration: Works with all AI module operations (chat, JSON output, tools)
- 9+ Claude Models: Supports Claude Opus 4.6, Sonnet 4.6, Haiku 4.5, and more
How It Works
This module uses OAuth access tokens obtained from the Claude CLI:
- Run
claude setup-tokento generate a token - Store the token securely using Drupal's Key module
- Select the Key in the module configuration
- The module automatically validates the token against Anthropic's API
Tokens are valid for approximately one year. When a token expires, simply generate a new one and update your Key — no complex OAuth refresh flow needed.
Technical Details
Authentication Method
OAuth tokens use Bearer authentication with a special beta header required by Anthropic:
Authorization: Bearer sk-ant-oat01-...anthropic-beta: oauth-2025-04-20anthropic-version: 2023-06-01
Architecture
- Extends:
OpenAiBasedProviderClientBase - Token Storage: Key module (required dependency)
- Model Discovery: Dynamic fetching from
/v1/modelsAPI endpoint - Fallback: Hardcoded model list if API is unavailable
- Dependency Injection: Follows Drupal 11 best practices throughout
Requirements
- Drupal 10.3+ or 11
- AI module (1.x)
- Key module (1.x) — Required
- Anthropic account with Claude Pro, Max, or Team subscription
- Claude CLI installed:
npm install -g @anthropic-ai/claude-code
Installation & Configuration
1. Install the Module
composer require drupal/ai_anthropic_provider_oauth drush en ai_anthropic_provider_oauth
2. Generate an OAuth Token
claude setup-token
This opens your browser for authentication and generates a token starting with sk-ant-oat01-
3. Create a Key
Navigate to Admin → Configuration → System → Keys (/admin/config/system/keys)
- Click "Add key"
- Name:
Anthropic OAuth Token - Key type:
Authentication - Key provider:
Configuration(dev) orEnvironment variable(production) - Paste your token in the Key value field
- Save
4. Configure the Provider
Navigate to Admin → Configuration → AI → Providers → Anthropic OAuth (/admin/config/ai/providers/anthropic-oauth)
- Select your Key in the "Access Token Configuration" section
- Save configuration
- The page will automatically validate your token against the Anthropic API
Available Models
The module dynamically fetches models from Anthropic's API. Current models include:
- Claude Opus 4.6 — Most capable model for complex tasks
- Claude Sonnet 4.6 — Balanced performance and speed
- Claude Haiku 4.5 — Fast and efficient
- And more (models update automatically)
Use Cases
✅ Appropriate Use
- Personal development and testing environments
- Internal tools for your organization (with active Claude subscription)
- Proof-of-concept and experimental projects
- Learning and exploring AI capabilities
- Websites where costs effectiveness is a key factor
❌ Not Recommended For
- Production websites serving external users
- Commercial applications
- High-volume API usage
- Mission-critical applications
For production use: Install AI Provider Anthropic with official API keys.
Comparison with AI Provider Anthropic
Feature ai_anthropic_provider_oauth ai_provider_anthropic Authentication OAuth Bearer tokens API keys (x-api-key) Token Sourceclaude setup-token
Anthropic Console
Token Validity
~1 year
Until revoked
Billing
Uses subscription
Separate API billing
ToS Compliance
Uncertain (third-party use)
Fully compliant
Production Use
Not recommended
Recommended
Troubleshooting
"No access token configured"
- Verify you created a Key at
/admin/config/system/keys - Verify you selected that Key in the module config
- Run
claude setup-tokenif you haven't generated a token
"Token validation failed"
Your token may be expired or revoked:
- Run
claude setup-tokento generate a fresh token - Update your Key with the new token value
- Verify your Claude subscription is active
Related Modules
- AI — Base AI module framework
- AI Provider Anthropic — Official API key provider (recommended for production)
- Key — Secure credential storage