claude-proxy-go

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2026 License: MIT

README

Claude Proxy Go

Go Version License

简体中文 | 繁體中文


Overview

Claude Proxy Go is a high-performance API proxy that translates Anthropic-compatible /v1/messages requests into OpenAI-compatible provider calls. It enables you to use OpenAI-compatible models (OpenAI, NVIDIA, OpenRouter, etc.) through the Anthropic API interface.

Features

  • Protocol Translation: Seamless conversion between Anthropic and OpenAI API formats
  • Multi-Provider Support: Works with any OpenAI-compatible provider (OpenAI, NVIDIA, OpenRouter, etc.)
  • Streaming Support: Full Server-Sent Events (SSE) streaming with Anthropic event sequence
  • Tool Calling: Support for tool definitions, tool_choice (auto/any/tool), and tool result handling
  • Advanced Parameter Mapping:
    • thinking.budget_tokensreasoning_effort (low/medium/high)
    • top_ktop_p mapping when top_p is not explicitly set
  • Retry Mechanism: Automatic retry with exponential backoff for rate limits (429) and server errors (5xx)
  • Proxy Support: HTTP/HTTPS/SOCKS5 proxy for upstream API calls
  • Production-Ready: Strict request validation, comprehensive error handling, configurable timeouts

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                    Claude Proxy Go                              │
│                                                                 │
│  ┌──────────────┐    ┌──────────────┐    ┌──────────────────┐  │
│  │   Handler    │───▶│  Converter   │───▶│   Eino Client    │  │
│  │    (HTTP)    │    │ (Anthropic   │    │    (OpenAI       │  │
│  │              │    │  → OpenAI)   │    │    Protocol)     │  │
│  └──────────────┘    └──────────────┘    └──────────────────┘  │
│         │                   │                     │            │
│         │           ┌───────┴───────┐             │            │
│         └──────────▶│     SSE       │◀────────────┘            │
│                     │  (Streaming)  │                         │
│                     └───────────────┘                         │
└─────────────────────────────────────────────────────────────────┘
                            │
                            ▼
            ┌─────────────────────────┐
            │    Upstream Provider    │
            │   (OpenAI/NVIDIA/       │
            │   OpenRouter/etc.)      │
            └─────────────────────────┘

Quick Start

Using Go Install
# Install directly from GitHub
go install github.com/hy-shine/claude-proxy-go/cmd/server@latest

# Run with config
claude-proxy-go -f configs/config.json
Using Binary
# Build
make build

# Run with default config
make run

# Or run with custom config
./bin/claude-proxy-go -f configs/config.json

Configuration

Create configs/config.json:

{
  "server": { "host": "0.0.0.0", "port": 8082 },
  "providers": {
    "openai": {
      "apiType": "openai",
      "apiKey": "sk-your-openai-key",
      "models": {
        "claude-sonnet": { "name": "gpt-4.1" }
      }
    }
  }
}

See CONFIG.md for full configuration options.

API

Health Check
curl http://localhost:8082/health
# {"status": "ok"}
Non-Streaming Request
curl -X POST http://localhost:8082/v1/messages \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello"}]
  }'
Streaming Request
curl -X POST http://localhost:8082/v1/messages \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet",
    "max_tokens": 1024,
    "stream": true,
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Development

# Run tests
make test

# Run with coverage
make cover

# Lint code
make lint

# Format code
make fmt

License

MIT License - see LICENSE file for details.

Directories

Path Synopsis
cmd
server command
internal
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL