arproxy worker

Cloudflare Worker · one file · no dependencies

A proxy that keeps the stream alive.

Point Claude Code, an OpenAI SDK, or plain curl at your own worker URL. It attaches the headers the upstream expects, drops the parameters it rejects, and refuses to hand you a broken stream.

Download arproxy.zip (v2) 16 KB · 4 files · read proxy.js before you run it

Cold start
0 ms
Dependencies
none
Retries
up to 3

Run it

Start on your own machine. Everything works against localhost first — deploy only once you have seen it answer.

00 Get the files Download arproxy.zip
    bash — arproxy
    Base URL while developing http://localhost:8787

    What it handles

    Streams that die before they start
    On /v1/messages the response is held back until the upstream sends message_start. If the stream drops before that, the request runs again — your client never sees the stump.
    Errors wearing a 200
    Some failures arrive with a success status and the error buried in the stream body. The first bytes are read and replayed, so a failure is caught and retried instead of forwarded.
    Parameters the upstream rejects
    temperature and top_p are stripped. Empty properties: [] schemas become {}. Tool results with no matching call are dropped before they cause a 400.
    Malformed UTF-16
    Lone surrogates are sanitized out of both directions, and standalone data: null events — which strict Anthropic clients treat as fatal — are removed from the stream.
    Clients that can't stream
    Every upstream call streams. If you asked for a plain response, the SSE is folded back into one JSON body in the shape your API actually speaks.
    Both API dialects
    Anthropic Messages and OpenAI Chat Completions on the same worker. A bare path is routed to /v1/chat/completions, so a misconfigured client still lands somewhere real.

    API

    Endpoints
    POST/v1/messagesAnthropic Messages
    POST/v1/chat/completionsOpenAI Chat Completions
    POST/v1/completionsOpenAI Completions
    GET/v1/modelsAvailable models
    GET/Setup page, printing the live base URL
    Variables
    UPSTREAM_ORIGINWhere requests are forwarded. Defaults to https://agentrouter.org.
    API_KEYUsed only when a client sends no key of its own. Optional.

    Set both in wrangler.toml under [vars], or in the Cloudflare dashboard. Keys sent by a client are forwarded upstream and never written down.