Claude Subscription Support
NeuroLink provides flexible access to Anthropic's Claude models through multiple subscription tiers and authentication methods. This guide covers setup, configuration, and best practices for each tier.
Overview
Claude is available through different subscription tiers, each offering varying levels of access, rate limits, and model availability:
| Tier | Access Method | Rate Limits | Best For |
|---|---|---|---|
| Free | claude.ai account | Limited messages | Exploration, personal use |
| Pro | OAuth + claude.ai | 5x Free tier | Professional use, higher volume |
| Max | OAuth + claude.ai | Unlimited | Heavy production, no rate limit worries |
| API | API Key | Pay-per-token | Production systems, programmatic access |
Subscription Tiers
The ClaudeSubscriptionTier type (defined in src/lib/types/subscriptionTypes.ts) supports these values:
"free"-- Free tier with basic access and limited usage"pro"-- Professional tier with higher limits and priority access"max"-- Maximum tier with highest limits (alias for max_5)"max_5"-- Max 5x usage tier"max_20"-- Max 20x usage tier"api"-- Direct API access tier for developers and enterprises
Free Tier:
- Basic access to Claude via claude.ai
- Limited message quota per day
- Access to Claude 3 Haiku and Claude 3.5 Haiku models only
- Good for exploring Claude's capabilities
Pro Subscription ($20/month):
- Higher usage limits than Free tier
- Priority access during peak times
- Access to Haiku and Sonnet model families (Claude 3 Haiku, Claude 3.5 Haiku, Claude 3.5 Sonnet, Claude 3.5 Sonnet V2, Claude Sonnet 4)
- No access to Opus models
Max Subscription ($100/month):
- Highest usage limits
- All models available, including Opus
- Available in Max, Max 5x, and Max 20x usage multiplier variants
API Access (Pay-per-use):
- Direct programmatic access
- No monthly subscription required
- Pay only for tokens used
- Full model selection (all models)
- Production-ready SLAs
Authentication Methods
NeuroLink supports two authentication methods for Claude access, defined by the AnthropicAuthMethod type:
"api_key"-- Traditional API key authentication"oauth"-- OAuth 2.0 authentication for subscription-based access
API Key Authentication (Recommended for Production)
The standard method using Anthropic API keys. Best for:
- Production deployments
- Server-side applications
- Predictable billing (pay-per-token)
- Full API control
OAuth Authentication (Claude Pro/Max)
OAuth authentication allows you to use your existing Claude Pro or Max subscription through NeuroLink. This is ideal for:
- Personal development using your existing Pro/Max subscription
- CLI usage without additional API costs
- Leveraging your subscription's included usage quota
When you authenticate with OAuth, you are redirected to claude.ai to sign in with your Claude account. After authorizing, you receive an authorization code to paste back into the CLI. NeuroLink then securely stores your tokens for future requests.
Setup Guide
API Key Setup (Standard)
Step 1: Get Your API Key
- Visit console.anthropic.com
- Sign in or create an account
- Navigate to API Keys section
- Click Create Key
- Copy your new API key (starts with
sk-ant-)
Step 2: Configure Environment
Set the API key in your environment:
# Required: Your Anthropic API key
export ANTHROPIC_API_KEY="sk-ant-api03-your-key-here"
# Optional: Default model
export ANTHROPIC_MODEL="claude-sonnet-4-20250514"
Step 3: Verify Configuration
# Using the CLI
pnpm run cli -- generate "Hello, Claude" --provider anthropic
# Or use the installed binary
neurolink generate "Hello, Claude" --provider anthropic
Step 4: SDK Usage
import { NeuroLink } from "@juspay/neurolink";
const neurolink = new NeuroLink();
const result = await neurolink.generate({
input: { text: "Explain machine learning in simple terms" },
provider: "anthropic",
model: "claude-sonnet-4-20250514",
temperature: 0.7,
maxTokens: 1000,
});
console.log(result.content);
OAuth Setup (Claude Pro/Max)
OAuth authentication allows you to use your Claude Pro or Max subscription through NeuroLink, leveraging your subscription quota instead of API billing.
OAuth authentication is designed for personal and development use. For production deployments, use API key authentication for better reliability and SLA guarantees.
Step 1: Start OAuth Authentication
Use the CLI to initiate the OAuth flow:
# Start OAuth authentication (interactive -- choose method)
pnpm run cli -- auth login anthropic
# Start OAuth authentication directly
pnpm run cli -- auth login anthropic --method oauth
# Or create an API key via OAuth (recommended for Pro/Max users)
pnpm run cli -- auth login anthropic --method create-api-key
The CLI supports three authentication methods for Anthropic:
| Method | Description |
|---|---|
api-key | Traditional API key authentication (pay-per-use) |
oauth | Direct OAuth for Claude Pro/Max subscriptions |
create-api-key | Create a real API key via OAuth using your account |
Step 2: Authorize in Browser
- Sign in to your Claude account in the browser (claude.ai)
- Review the requested permissions
- Click Authorize to grant access
- Copy the authorization code shown on the page
Step 3: Complete Authentication
Paste the authorization code back into the CLI when prompted:
Paste the authorization code: <paste-your-code-here>
The CLI will exchange the code for tokens and store them securely.
Step 4: Verify Authentication
# Check authentication status
pnpm run cli -- auth status
# Check status for a specific provider
pnpm run cli -- auth status anthropic
# Output example:
# Anthropic [Authenticated]
# Method: oauth
# Subscription: pro
# Token Expires: 2026-02-10T12:00:00Z
# Refresh Token: Available
Token Management
OAuth tokens are managed automatically by NeuroLink:
# View token information
pnpm run cli -- auth status
# Refresh tokens manually (usually automatic)
pnpm run cli -- auth refresh anthropic
# Revoke authentication
pnpm run cli -- auth logout anthropic
Token Storage Location:
Credentials are stored at ~/.neurolink/tokens.json with 0o600 file permissions (via the TokenStore class). Legacy CLI-saved credentials may also exist at ~/.neurolink/anthropic-credentials.json. The file format is:
{
"type": "oauth",
"oauth": {
"accessToken": "...",
"refreshToken": "...",
"expiresAt": 1740000000000,
"tokenType": "Bearer",
"scope": "user:profile user:inference"
},
"provider": "anthropic",
"subscriptionTier": "pro",
"createdAt": 1739000000000,
"updatedAt": 1739000000000
}
Note: expiresAt is stored as Unix milliseconds (Date.now() scale), not seconds.
The TokenStore class (at src/lib/auth/tokenStore.ts) provides multi-provider token storage with XOR-based obfuscation at ~/.neurolink/tokens.json.
SDK OAuth Usage
To use OAuth authentication in the SDK, pass authMethod: "oauth" and an oauthToken object to the Anthropic provider constructor via the NeuroLink configuration:
import { NeuroLink } from "@juspay/neurolink";
const neurolink = new NeuroLink({
provider: "anthropic",
model: "claude-sonnet-4-20250514",
authMethod: "oauth",
oauthToken: {
accessToken: "your-access-token",
refreshToken: "your-refresh-token",
expiresAt: Date.now() + 3600000, // milliseconds (Date.now() scale)
},
});
const result = await neurolink.generate({
prompt: "Hello, Claude!",
});
Alternatively, the provider auto-detects OAuth credentials from:
- Stored credentials file (
~/.neurolink/tokens.jsonor legacy~/.neurolink/anthropic-credentials.json) -- highest priority - Environment variables
ANTHROPIC_OAUTH_TOKENorCLAUDE_OAUTH_TOKEN
If either source provides a valid OAuth token, the provider automatically switches to OAuth mode without any explicit authMethod configuration.
AnthropicProvider Direct Usage
For advanced use cases, you can instantiate AnthropicProvider directly with AnthropicProviderConfig:
import AnthropicProvider from "./lib/providers/anthropic.js";
const provider = new AnthropicProvider(
"claude-sonnet-4-20250514", // model name
undefined, // SDK instance (optional)
{
authMethod: "oauth",
oauthToken: {
accessToken: "your-token",
refreshToken: "your-refresh-token",
expiresAt: Date.now() + 3600000,
},
subscriptionTier: "pro",
enableBetaFeatures: true, // default: true
},
);
The AnthropicProviderConfig interface accepts:
| Property | Type | Default | Description |
|---|---|---|---|
authMethod | "api_key" | "oauth" | Auto-detected | Authentication method |
subscriptionTier | ClaudeSubscriptionTier | Auto-detected | Subscription tier for model access validation |
enableBetaFeatures | boolean | true | Include beta headers for experimental features |
oauthToken | OAuthToken | Auto-detected | OAuth token for OAuth authentication |
apiKey | string | From env | API key for API key authentication |
Auto-Refresh Behavior
The Anthropic provider automatically refreshes expired OAuth tokens before every generate() and stream() call via the refreshAuthIfNeeded() method. This happens transparently and requires no user intervention.
How auto-refresh works:
- Before each API call, the provider checks the
expiresAttimestamp on the OAuth token - If the token is expired or within 5 minutes of expiring, a refresh is attempted
- The refresh request is sent to
https://console.anthropic.com/v1/oauth/tokenusing the stored refresh token - The refreshed token is stored both in-memory (mutated in-place on the same object reference so the fetch wrapper picks it up) and persisted to
~/.neurolink/anthropic-credentials.json - If no refresh token is available and the token is expired, an
AuthenticationErroris thrown
The createOAuthFetch() function accepts a getter function () => string that is called on each request to retrieve the current access token. Since refreshAuthIfNeeded() mutates oauthToken.accessToken in-place (rather than replacing the object), the getter — () => tokenRef.accessToken — returns the refreshed value automatically on subsequent requests without needing to re-create the fetch wrapper.
Manual refresh via CLI:
pnpm run cli -- auth refresh anthropic
Configuration
Environment Variables
| Variable | Description | Default | Required |
|---|---|---|---|
ANTHROPIC_API_KEY | API key for authentication | -- | Yes* |
ANTHROPIC_MODEL | Default model to use | claude-3-5-sonnet-20241022 | No |
ANTHROPIC_OAUTH_TOKEN | OAuth token (JSON or plain string) | -- | No |
CLAUDE_OAUTH_TOKEN | OAuth token (fallback env var) | -- | No |
ANTHROPIC_SUBSCRIPTION_TIER | Explicit subscription tier | Auto-detected | No |
*Required for API key authentication. Not required when using OAuth.
Subscription Tier Detection
The provider detects the subscription tier in this priority order:
- Explicit
subscriptionTierpassed inAnthropicProviderConfig ANTHROPIC_SUBSCRIPTION_TIERenvironment variable (valid values:free,pro,max,max_5,max_20,api)- Inferred from OAuth token scopes (if present)
- Default:
"pro"when OAuth token is present,"api"when using API key
CLI Options
# Specify provider and model
pnpm run cli -- generate "Your prompt" --provider anthropic --model claude-sonnet-4-20250514
# Set temperature and max tokens
pnpm run cli -- generate "Your prompt" --provider anthropic --temperature 0.7 --max-tokens 2000
# Use streaming output
pnpm run cli -- stream "Tell me a story" --provider anthropic
# Specify auth method and subscription tier
pnpm run cli -- generate "Your prompt" \
--provider anthropic \
--authMethod oauth \
--subscriptionTier pro
The CLI also supports anthropic-subscription as a provider alias that indicates subscription tier support.
Beta Features
Anthropic regularly releases new features in beta. NeuroLink includes beta headers automatically when enableBetaFeatures is true (the default).
Beta Headers
For API key authentication, the following beta headers are included:
anthropic-beta: claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14
These correspond to the AnthropicBetaFeature enum values in src/lib/constants/enums.ts:
| Enum Value | Header Value |
|---|---|
CLAUDE_CODE | claude-code-20250219 |
INTERLEAVED_THINKING | interleaved-thinking-2025-05-14 |
FINE_GRAINED_STREAMING | fine-grained-tool-streaming-2025-05-14 |
For OAuth authentication, the fetch wrapper uses different beta headers:
anthropic-beta: oauth-2025-04-20,interleaved-thinking-2025-05-14
The oauth-2025-04-20 header is required for OAuth-authenticated requests. The claude-code-20250219 header is conditionally included only if the original request headers already contain it.
Model Availability by Tier
Model Access Matrix
Model access is defined in MODEL_TIER_ACCESS in src/lib/models/anthropicModels.ts:
| Model | Free | Pro | Max/Max_5/Max_20 | API |
|---|---|---|---|---|
claude-3-haiku-20240307 (Claude 3 Haiku) | Yes | Yes | Yes | Yes |
claude-3-5-haiku-20241022 (Claude 3.5 Haiku) | Yes | Yes | Yes | Yes |
claude-3-5-sonnet-20241022 (Claude 3.5 Sonnet) | No | Yes | Yes | Yes |
claude-3-5-sonnet-v2-20241022 (Claude 3.5 Sonnet V2) | No | Yes | Yes | Yes |
claude-sonnet-4-20250514 (Claude Sonnet 4) | No | Yes | Yes | Yes |
claude-3-opus-20240229 (Claude 3 Opus) | No | No | Yes | Yes |
claude-opus-4-20250514 (Claude Opus 4) | No | No | Yes | Yes |
Key observations:
- Free tier only gets Haiku models (Claude 3 Haiku and Claude 3.5 Haiku)
- Pro tier gets Haiku and Sonnet models, but not Opus
- Max tiers (max, max_5, max_20) and API have access to all models (wildcard
"*")
Default Models by Tier
Each tier has a recommended default model (from DEFAULT_MODELS_BY_TIER):
| Tier | Default Model |
|---|---|
| Free | claude-3-5-haiku-20241022 |
| Pro | claude-sonnet-4-20250514 |
| Max | claude-opus-4-20250514 |
| Max_5 | claude-opus-4-20250514 |
| Max_20 | claude-opus-4-20250514 |
| API | claude-sonnet-4-20250514 |
Model Tier Enforcement
When the provider detects that the requested model is not available for the user's subscription tier, it automatically falls back to the recommended model for that tier and logs a warning:
// If a Pro user requests an Opus model:
// - The provider logs a warning
// - Falls back to claude-sonnet-4-20250514 (the Pro default)
You can validate model access programmatically:
import {
isModelAvailableForTier,
getRecommendedModelForTier,
getModelCapabilities,
ModelAccessError,
} from "./lib/providers/anthropic.js";
// Check if a model is available
const available = isModelAvailableForTier("claude-opus-4-20250514", "pro");
// Returns: false (Opus requires max or api tier)
// Get recommended model for a tier
const recommended = getRecommendedModelForTier("pro");
// Returns: "claude-sonnet-4-20250514"
// Get model metadata
const capabilities = getModelCapabilities("claude-sonnet-4-20250514");
// Returns: { displayName: "Claude Sonnet 4", contextWindow: 200000, maxOutputTokens: 64000, ... }
Choosing the Right Model
import { NeuroLink } from "@juspay/neurolink";
const neurolink = new NeuroLink();
// For quick, cost-effective responses (Free tier compatible)
const quickResult = await neurolink.generate({
input: { text: "Summarize this text..." },
provider: "anthropic",
model: "claude-3-5-haiku-20241022",
});
// For balanced performance (Pro tier and above)
const balancedResult = await neurolink.generate({
input: { text: "Analyze this code..." },
provider: "anthropic",
model: "claude-sonnet-4-20250514",
});
// For complex reasoning tasks (Max/API tier only)
const complexResult = await neurolink.generate({
input: { text: "Solve this complex problem..." },
provider: "anthropic",
model: "claude-opus-4-20250514",
});