Skip to content

Conversation

@siddharthsambharia-portkey
Copy link
Contributor

Description

Motivation

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing

Screenshots (if applicable)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

@matter-code-review
Copy link
Contributor

Code Quality new feature

Summary By MatterAI MatterAI logo

🔄 What Changed

Added support for Claude Code Max plans via Portkey by enhancing Anthropic API configuration. Introduced new endpoint mapping for token counting (/messages/count_tokens) and refined header injection logic for beta features and API versioning.

🔍 Impact of the Change

Enables usage of Anthropic's latest models and features through Portkey, improving flexibility for users. The changes are backward-compatible and align with Anthropic’s evolving API standards.

📁 Total Files Changed

File ChangeLog
API Config src/providers/anthropic/api.ts Added messagesCountTokens route and updated header logic to support dynamic beta/version headers for chat completion

🧪 Test Added/Recommended

Recommended

  • Add unit test for messagesCountTokens endpoint resolution
  • Add integration test validating anthropic-beta and anthropicVersion headers are correctly set
  • Test fallback behavior when providerOptions or headers are missing

🔒 Security Vulnerabilities

No security vulnerabilities detected. API key handling remains secure via header injection with fallback precedence.

⏳ Estimated code review effort

LOW (~7 minutes)

Tip

Quality Recommendations

  1. Add explicit type for providerOptions to improve type safety

  2. Include validation for anthropic-beta and version format to prevent malformed headers

  3. Add unit test coverage for endpoint routing logic

♫ Tanka Poem

Code flows through wires,
Claude's mind now opens wide—
Max plans take flight.
Tokens counted, paths aligned,
AI speaks in clearer tones. 🚀

Sequence Diagram

sequenceDiagram
    participant Client
    participant AnthropicAPIConfig
    participant AnthropicAPI

    Note over Client,AnthropicAPIConfig: Initialization

    Client->>AnthropicAPIConfig: chatComplete(request)
    AnthropicAPIConfig->>AnthropicAPIConfig: headers({providerOptions, fn: 'chatComplete'})
    AnthropicAPIConfig-->>AnthropicAPI: X-API-Key = providerOptions.apiKey or requestHeaders['x-api-key']
    AnthropicAPIConfig-->>AnthropicAPI: anthropic-beta = providerOptions.anthropicBeta or 'messages-2023-12-15'
    AnthropicAPIConfig-->>AnthropicAPI: anthropic-version = providerOptions.anthropicVersion or '2023-06-01'

    Client->>AnthropicAPIConfig: getEndpoint('messagesCountTokens')
    AnthropicAPIConfig-->>Client: returns '/messages/count_tokens'

    Note over AnthropicAPI: Request Sent to Anthropic
Loading

@matter-code-review
Copy link
Contributor

Review of Anthropic API configuration changes for header handling, versioning, and new endpoint support.

@narengogi narengogi changed the title feat: support claude code max plans on Portkey feat: support claude code oauth/max plans on Portkey Oct 21, 2025
providerOptions?.['anthropicVersion'] ??
gatewayRequestBody?.['anthropic_version'] ??
'2023-06-01';
providerOptions?.['anthropicBeta'] ?? 'messages-2023-12-15';
Copy link
Collaborator

@narengogi narengogi Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls revert the changes on ln 13 and 14
do not change the precedence order for betaHeader. This would break existing flows

Copy link
Collaborator

@narengogi narengogi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test

Copy link
Collaborator

@narengogi narengogi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please sign your commits

@siddharthsambharia-portkey
Copy link
Contributor Author

please sign your commits

yes sir will do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants