Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bedrock-proxy (Rust / Cloudflare Worker)

Deploy to Cloudflare

Anthropic Messages API → AWS Bedrock proxy, built with workers-rs (WASM). Receives standard Anthropic-format requests and forwards them to Bedrock Claude models with SigV4 signing. Zero logging.

Call contract

POST https://<worker-domain>/v1/messages?caching=true
x-api-key: <accessKeyId>:<secretAccessKey>:<region>   (IAM)
           or <bearerApiKey>:<region>                 (Bedrock API key)
content-type: application/json

body: Anthropic Messages format, plus "model": "<Bedrock modelId or inference profile ARN>"
  • model is removed from the body and moved into the Bedrock URL path (percent-encoded, so ARNs work).
  • anthropic_version: "bedrock-2023-05-31" is injected.
  • stream: true/invoke-with-response-stream; the AWS vnd.amazon.eventstream binary framing is re-encoded as SSE (event: <type>\ndata: <json>\n\n), matching Anthropic's streaming shape.

Query parameters

  • ?caching=true — inject cache_control: {type:"ephemeral"} breakpoints:
    • last text block of the system array (shared system/character prefix)
    • last text block of the two most recent assistant messages (rolling conversation cache)
    • 3 breakpoints max, within Anthropic's 4-breakpoint limit. Verify cache hits via usage.cache_creation_input_tokens / usage.cache_read_input_tokens in the response.
  • ?thinking=adaptive|enabled&thinkingBudget=N — extended thinking passthrough.
  • ?effort=low|medium|high|xhigh|maxoutput_config.effort passthrough.

No serviceTier/flex support (removed intentionally; some models reject it).

Build & deploy

npx wrangler deploy

(wrangler deploy runs cargo install worker-build && worker-build --release via the [build] command in wrangler.toml.)

Test

curl -s 'https://<worker>/v1/messages?caching=true' \
  -H 'x-api-key: AKIA...:SECRET...:us-west-2' \
  -H 'content-type: application/json' \
  -d '{
    "model": "us.anthropic.claude-opus-4-6-v1",
    "max_tokens": 256,
    "system": [{"type":"text","text":"<long shared prefix>"}],
    "messages": [{"role":"user","content":"hello"}]
  }' | jq .usage

About

Anthropic Messages API → AWS Bedrock proxy (Rust Cloudflare Worker, prompt-caching first)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages