feat(providers): add anthropic-discount provider - #2465
Conversation
Add an Anthropic-compatible 'anthropic-discount' provider that behaves exactly like upstream Anthropic but resolves its base URL and API key from environment variables (LLM_ANTHROPIC_DISCOUNT_BASE_URL / LLM_ANTHROPIC_DISCOUNT_API_KEY), mirroring the avalanche stealth pattern. Includes Claude Opus 4.8 with a 10% discount on all prices. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughThis PR adds end-to-end support for a new ChangesAnthropic Discount Provider Support
Sequence DiagramsequenceDiagram
participant Client
participant Gateway as Gateway
participant ProviderTools as ProviderTools
participant AnthropicDiscount as anthropic-discount
Client->>Gateway: Chat request (provider: anthropic-discount)
Gateway->>Gateway: resolveProviderContext (headers, beta markers)
Gateway->>Gateway: prepareRequestBody (cache control, messages)
Gateway->>AnthropicDiscount: POST /messages (streaming)
AnthropicDiscount-->>Gateway: Streaming deltas (content/tool-calls/reasoning)
Gateway->>Gateway: extractContent (from delta)
Gateway->>Gateway: extractToolCalls (delta enrichment)
Gateway->>Gateway: extractReasoning (from delta)
Gateway->>Gateway: extractTokenUsage (from delta)
Gateway->>ProviderTools: transformStreamingToOpenai
Gateway->>ProviderTools: parseProviderResponse
Gateway->>ProviderTools: mapFinishReasonToOpenai
Gateway-->>Client: Transformed streaming response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a new anthropic-discount provider that mirrors Anthropic's behavior but routes through a configurable endpoint (LLM_ANTHROPIC_DISCOUNT_BASE_URL / LLM_ANTHROPIC_DISCOUNT_API_KEY) and exposes Claude Opus 4.8 at 10% lower prices. The provider plugs into every Anthropic-specific code branch across model/provider definitions, request transforms, response/stream parsing, headers, finish-reason mapping, and logs.
Changes:
- Define
anthropic-discountprovider (env-based apiKey + baseUrl) and add a discounted Claude Opus 4.8 mapping. - Endpoint resolution reads the discount base URL and reuses Anthropic's
/v1/messagespath. - Group
anthropic-discountwithanthropic(andvertex-anthropicwhere applicable) across gateway request/response/streaming/header/finish-reason/log branches.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/models/src/providers.ts | Registers the new anthropic-discount provider with required env vars. |
| packages/models/src/models/anthropic.ts | Adds Claude Opus 4.8 mapping for anthropic-discount with 10% lower prices. |
| packages/actions/src/get-provider-endpoint.ts | Resolves discount base URL from env and routes to /v1/messages. |
| packages/actions/src/get-provider-headers.ts | Includes anthropic-discount in Anthropic header path (x-api-key + beta features). |
| packages/actions/src/prepare-request-body.ts | Treats anthropic-discount as Anthropic for cache-control and request-body transform. |
| packages/actions/src/transform-anthropic-messages.ts | Enables cache-control auto-injection for anthropic-discount. |
| apps/gateway/src/chat/tools/parse-provider-response.ts | Parses non-streaming responses identically to Anthropic. |
| apps/gateway/src/chat/tools/transform-streaming-to-openai.ts | Routes streaming chunks through the Anthropic transform. |
| apps/gateway/src/chat/tools/transform-response-to-openai.ts | Routes non-streaming responses through the Anthropic transform. |
| apps/gateway/src/chat/tools/extract-content.ts | Extracts streaming text content for anthropic-discount. |
| apps/gateway/src/chat/tools/extract-reasoning.ts | Extracts streaming reasoning for anthropic-discount. |
| apps/gateway/src/chat/tools/extract-tool-calls.ts | Extracts streaming tool-use blocks for anthropic-discount. |
| apps/gateway/src/chat/tools/extract-token-usage.ts | Reads Anthropic-style usage fields for anthropic-discount. |
| apps/gateway/src/chat/tools/map-finish-reason-to-openai.ts | Maps Anthropic finish reasons for anthropic-discount. |
| apps/gateway/src/chat/tools/resolve-provider-context.ts | Applies Anthropic temperature/top_p rule and beta headers to anthropic-discount. |
| apps/gateway/src/chat/chat.ts | Includes anthropic-discount in all Anthropic branches (headers, healing, streaming handling). |
| apps/gateway/src/lib/logs.ts | Unified finish-reason mapping covers anthropic-discount. |
| .env.example | Documents the new env vars. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Match anthropic-discount prices exactly to the upstream anthropic mapping and express the 10% reduction with the mapping-level discount flag instead of hardcoded discounted prices. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add claude-opus-4-7 to the anthropic-discount provider with prices matching the upstream anthropic mapping and a 10% discount flag, and set the provider's routing priority to 1.5. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Summary
Adds a new
anthropic-discountprovider that behaves exactly like upstream Anthropic for all request/response handling, with two differences:LLM_ANTHROPIC_DISCOUNT_BASE_URL/LLM_ANTHROPIC_DISCOUNT_API_KEY), following the same stealth pattern as theavalancheprovider.Currently exposes a single model: Claude Opus 4.8 (
anthropic-discount/claude-opus-4-8).What changed
packages/models: newanthropic-discountprovider definition (env-basedapiKey+baseUrl);claude-opus-4-8gains ananthropic-discountprovider mapping with all prices reduced by 10%.packages/actions: endpoint resolution readsLLM_ANTHROPIC_DISCOUNT_BASE_URLand appends/v1/messages; headers, request-body transform, and Anthropic message/cache-control handling treatanthropic-discountidentically toanthropic.apps/gateway: every Anthropic-specific branch (content/reasoning/tool-call/token-usage extraction, streaming + non-streaming transforms, finish-reason mapping, response healing, effort/structured-output beta headers, temperature/top_p stripping, logs) now also matchesanthropic-discount..env.example: documents the two new env vars.Token and base-URL resolution flow through the existing generic env machinery, so no per-provider plumbing was needed beyond the protocol branches.
Testing
pnpm format✅pnpm build✅pnpm test:unit✅ (1675 passed)End-to-end verification against a real discounted endpoint is pending — the proxy will be run separately.
🤖 Generated with Claude Code
Summary by CodeRabbit