Bring Your Own Key for Amp CLI. A tiny Cloudflare Worker that swaps
amp's AI calls onto your own Anthropic / OpenAI / Gemini keys and passes everything else through toampcode.com.
| Path | Forwards to |
|---|---|
POST /api/provider/anthropic/v1/messages |
your Anthropic |
POST /api/provider/openai/v1/{chat/completions,responses} |
your OpenAI |
POST /api/provider/google/v1beta/models/{action} |
your Gemini |
| anything else | ampcode.com with your stored ampcode token |
SHARED_SECRET lives in Cloudflare Secrets Store and authenticates the local amp CLI to this worker. All other state — the ampcode token and per-provider base_url + api_key — lives in a KV namespace and is set through the admin UI at /.
The Deploy to Cloudflare button creates the KV namespace and lets you select or create a Secrets Store entry for SHARED_SECRET. Generate the value with openssl rand -hex 32 and paste it when prompted. Done.
pnpm install
# Create a Secrets Store (skip if you already have one)
wrangler secrets-store store create default --remote
wrangler secrets-store store list --remote # copy the store_id
# Create the secret entry; paste `openssl rand -hex 32` when prompted
wrangler secrets-store secret create <STORE_ID> \
--name ampcode-byok-shared-secret \
--scopes workers \
--remote
# Paste <STORE_ID> into wrangler.jsonc → secrets_store_secrets[0].store_id
pnpm run deploy # also auto-creates the STORE KV namespace- Open
https://<your-worker>.workers.dev/, unlock with the same secret, fill in the ampcode token and your provider keys. - Point amp at the worker by adding the URL to
~/.config/amp/settings.json:Then run{ "amp.url": "https://<your-worker>.workers.dev" }amp login. On the page that opens, paste the sameSHARED_SECRETand click Authorize. Amp stores it locally and uses it as its API key from then on.
Secrets Store has a separate local-mode namespace; mirror the production entry into it:
pnpm install
# Same store_id you used in wrangler.jsonc, but without --remote.
wrangler secrets-store secret create <STORE_ID> \
--name ampcode-byok-shared-secret \
--scopes workers \
--value "$(openssl rand -hex 32)"
pnpm run devpnpm run typecheck for tsc --noEmit; pnpm run cf-typegen after binding changes.
MIT.