Skip to main content

🔄 Transparent Provider Switching

Your application talks to one LLM API (e.g., OpenAI), but you want to route traffic to a different provider (e.g., Anthropic) without modifying any application code.

📋 Scenario

Your app sends OpenAI-format requests to http://127.0.0.1:11510/v1/chat/completions. You want these requests forwarded to Anthropic with format conversion.

⚙️ Setup

1️⃣ Configure Downstreams

downstreams:
- id: openai
name: OpenAI
api_formats: [openai]
base_url: https://api.openai.com/v1
api_key: sk-proj-...
output_model_ids:
- gpt-4o

- id: anthropic
name: Anthropic
api_formats: [anthropic]
base_url: https://api.anthropic.com
api_key: sk-ant-...
output_model_ids:
- claude-sonnet-4-20250514

2️⃣ Create a Rule with Format Conversion (Optional)

rules:
- id: chat-anthropic
name: Chat Completions -> Anthropic
pattern_path: /v1/chat/completions
match_format: [openai]
match_downstream_format: [anthropic]
match_downstreams: [anthropic]
pipeline_config:
- plugin_id: openai2anthropic
is_enabled: true

The openai2anthropic plugin:

  • Converts OpenAI Chat Completion request format to Anthropic Messages format
  • Maps model names (e.g., gpt-4oclaude-sonnet-4)
  • Extracts system prompts into Anthropic's system field
  • Handles streaming responses (SSE event conversion)

Tip: Since the Anthropic downstream declares api_formats: [anthropic], auto-translation kicks in automatically — the explicit openai2anthropic plugin in the rule is redundant but harmless (deduplication prevents double-conversion). The format filters on this rule ensure it only matches when the request is OpenAI format and the resolved downstream is Anthropic.

3️⃣ Point Your App

Configure your application to use Tresor as the endpoint:

# Python example
client = OpenAI(
base_url="http://127.0.0.1:11510/v1",
api_key="sk-proxy-123"
)

response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)

The app thinks it's talking to OpenAI. Tresor converts the request, forwards it to Anthropic, converts the response back, and returns it — all transparently.