Skip to content

Conversation

@wilsonccccc
Copy link
Contributor

@wilsonccccc wilsonccccc commented Jul 20, 2025

Add Claude Code Support to Forge

Summary

Adds Claude Code compatibility to Forge, enabling Anthropic API format requests to route through Forge's provider infrastructure while maintaining full API compatibility.

What's New

  • New Endpoints: /v1/messages and /v1/messages/count_tokens
  • Format Conversion: Bidirectional Anthropic ↔ OpenAI conversion
  • Streaming Support: Real-time SSE event conversion
  • Full Feature Support: Tools, multimodal, system prompts, token counting
  • Forge Integration: Uses existing API keys, provider routing, and caching

Key Benefits

  • Provider Flexibility: Route Claude requests to any Forge provider (OpenAI, Anthropic, etc.)
  • Drop-in Replacement: Change base URL and API key, keep everything else
  • Unified Management: Single API key for all AI providers
  • Cost Optimization: Use cheaper providers for Claude-format requests

Files Added

  • app/api/schemas/anthropic.py # Anthropic schemas
  • app/utils/anthropic_converter.py # Format conversion
  • app/utils/anthropic_streaming.py # Streaming conversion
  • app/api/routes/claude_code.py # Claude Code endpoints
  • examples/claude_code_example.py # Usage examples
  • docs/claude_code_support.md # Documentation

Migration

  1. Configure Forge with provider API keys
  2. Update Claude Code base URL: https://api.anthropic.com/v1http://localhost:8000
  3. Replace Anthropic API key with Forge API key
  4. Done! 🎉

Testing

  • ✅ Core conversion logic
  • ✅ Streaming and non-streaming
  • ✅ Tool usage and multimodal
  • ✅ Error handling and validation

No breaking changes - purely additive feature.

@Dokujaa
Copy link
Contributor

Dokujaa commented Jul 20, 2025

Cloned to local and works properly. I think using tiktoken was clever. Solid implementation!

@Dokujaa
Copy link
Contributor

Dokujaa commented Jul 20, 2025

Cloned to local and works properly. I think using tiktoken was clever. Solid implementation!

Minor improvement: I noticed that prox.py and claude_code.py have duplicate _get_allowed_provider_names functions with similar logic. I am wondering if we could combine this into one function. Otherwise, I think this is solid!

@wilsonccccc
Copy link
Contributor Author

Cloned to local and works properly. I think using tiktoken was clever. Solid implementation!

Minor improvement: I noticed that prox.py and claude_code.py have duplicate _get_allowed_provider_names functions with similar logic. I am wondering if we could combine this into one function. Otherwise, I think this is solid!

Addressed

@wilsonccccc wilsonccccc merged commit 3e98194 into TensorBlock:main Jul 21, 2025
3 checks passed
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.

3 participants