Streaming that behaves
SSE relay with terminal-frame validation, first-byte and idle guards, and cancellation that is recorded separately from upstream failure.
Translate OpenAI Chat, Anthropic Messages, Gemini, and Responses — with streaming that holds, tools that survive the trip, and failover that knows when to stop.
Every protocol has its own shape. Any2API keeps the useful parts and drops the accidental ones.
SSE relay with terminal-frame validation, first-byte and idle guards, and cancellation that is recorded separately from upstream failure.
Tool calls, arguments, and names survive conversion. Names are normalized upstream and restored for the client.
Ordered upstream chains, cooldowns, retry-after handling, and per-exception budgets. Committed streams never replay.
Responses requests with background: true become managed tasks: create, poll, cancel, and resume without holding the client connection.
Health, model discovery, request ring, metrics, audit, and usage. Admin routes stay off unless an admin key is configured.
No telemetry. No credentials in the repository. Public access is opt-in and off by default; admin should stay on loopback.
The entry format is parsed into a small intermediate representation. The upstream renderer writes the protocol it needs. The response makes the trip back — or stays byte-identical when the protocols match.
Chat, Messages, Gemini, or Responses — including stream flags and tools.
Model allowlists, health, cooldowns, and task-face rules decide which upstream gets the attempt.
Cross-protocol requests go through IR; same-protocol requests keep their bytes.
Stream frames, validate terminals, record attempts, and never replay a committed stream.
POST /v1/chat/completions
{
"model": "example-model",
"messages": [{"role": "user", "content": "Hello"}],
"stream": true
}
Build the Go binary, point it at one upstream, and keep the service on loopback.
git clone https://github.com/dwgx/any2api.git
cd any2api/src
go build -o any2api ./cmd/any2api
cp config.example.yaml ../config.yaml
../any2api -config ../config.yaml
127.0.0.1:8787upstreams:
- name: primary
protocol: openai_chat
base_url: https://api.example.com/v1
api_key: ${UPSTREAM_API_KEY}
models:
- id: example-model
upstream_model: upstream-model-name
upstreams: ["primary"]
Any2API does not collect upstream credentials from clients. This repository contains no accounts, cookies, or production keys. Public access is a deliberate, opt-in switch.
Read the security policy${ENV} references or an untracked config.yaml.127.0.0.1; terminate TLS at a reviewed proxy.