Protocol transport layer · Experimental

One gateway.
Every format.

Translate OpenAI Chat, Anthropic Messages, Gemini, and Responses — with streaming that holds, tools that survive the trip, and failover that knows when to stop.

Go 1.26Apache-2.0No telemetry
Client formats
OpenAI Chat Anthropic Gemini Responses
Any2APItranslate · route · observe healthy
Upstream protocols
OpenAI Chat Anthropic Gemini Responses
SSEtoolsfailovertasks
Capabilities

Built for the messy middle.

Every protocol has its own shape. Any2API keeps the useful parts and drops the accidental ones.

Streaming that behaves

SSE relay with terminal-frame validation, first-byte and idle guards, and cancellation that is recorded separately from upstream failure.

SSEcancelusage

Tools across dialects

Tool calls, arguments, and names survive conversion. Names are normalized upstream and restored for the client.

toolstool_useround-trip

Failover with judgment

Ordered upstream chains, cooldowns, retry-after handling, and per-exception budgets. Committed streams never replay.

failovercooldownretry-after

Background tasks

Responses requests with background: true become managed tasks: create, poll, cancel, and resume without holding the client connection.

responsestasksresume

Observable by default

Health, model discovery, request ring, metrics, audit, and usage. Admin routes stay off unless an admin key is configured.

healthmetricsaudit

Private by design

No telemetry. No credentials in the repository. Public access is opt-in and off by default; admin should stay on loopback.

no telemetrypublic offenv refs
SSE frames flowing through Any2API with a validated terminal frame
A stream is a contract: forward frames, validate the terminal, never replay after commit.
Architecture

Convert once.
Route anywhere.

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.

  1. 01
    Parse the entry

    Chat, Messages, Gemini, or Responses — including stream flags and tools.

  2. 02
    Choose the chain

    Model allowlists, health, cooldowns, and task-face rules decide which upstream gets the attempt.

  3. 03
    Convert or pass through

    Cross-protocol requests go through IR; same-protocol requests keep their bytes.

  4. 04
    Relay and observe

    Stream frames, validate terminals, record attempts, and never replay a committed stream.

endpoint
POST /v1/chat/completions
{
  "model": "example-model",
  "messages": [{"role": "user", "content": "Hello"}],
  "stream": true
}
Same gateway. Different dialects. One upstream chain.
Client formats on the left, Any2API in the middle, upstream protocols on the right
Convert once when protocols differ. Keep bytes intact when they match.
Quickstart

From clone to first request.

Build the Go binary, point it at one upstream, and keep the service on loopback.

terminal
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
Default listener: 127.0.0.1:8787
config.yamlminimal
upstreams:
  - 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"]
Credentials stay in the environment or an untracked local file.
Security & privacy

Your keys stay yours.

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
  • No secrets in git. Use ${ENV} references or an untracked config.yaml.
  • Loopback first. Bind to 127.0.0.1; terminate TLS at a reviewed proxy.
  • Public off by default. Sessions, access keys, and limits are opt-in.
  • Admin off by default. No admin key means no admin routes.
Security posture: public surface off, loopback bind, environment references, admin key required
Public surface off by default. Credentials by reference.