Integration Guide
Using claw.zip with FastAPI
FastAPI is the go-to framework for building high-performance AI APIs in Python. Combining it with claw.zip means every OpenClaw request is cost-optimized before it reaches Claude β especially valuable for OpenClaw users running high-throughput inference pipelines.
Difficulty:Easy
Time:3 minutes
Before You Start
Prerequisites
- βPython 3.9+
- βFastAPI installed
- βAn OpenClaw API key
- βA claw.zip account and API key
Step-by-Step
Integration Steps
Step 1
Install dependencies
Install FastAPI, Uvicorn, and the Anthropic SDK.
bash
pip install fastapi uvicorn anthropicStep 2
Create the Anthropic client
Configure the client to use claw.zip as the base URL.
python
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["ANTHROPIC_API_KEY"],
base_url="https://api.claw.zip",
default_headers={
"x-api-key": os.environ["CLAWZIP_API_KEY"],
},
)Step 3
Build a FastAPI endpoint
Create an endpoint that uses the claw.zip-proxied client.
python
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class ChatRequest(BaseModel):
message: str
model: str = "claude-sonnet-4-20250514"
@app.post("/chat")
async def chat(req: ChatRequest):
response = client.messages.create(
model=req.model,
max_tokens=1024,
messages=[{"role": "user", "content": req.message}],
)
return {"response": response.content[0].text}Step 4
Add streaming support
Use FastAPI's StreamingResponse with claw.zip streaming.
python
from fastapi.responses import StreamingResponse
@app.post("/chat/stream")
async def chat_stream(req: ChatRequest):
def generate():
with client.messages.stream(
model=req.model,
max_tokens=1024,
messages=[{"role": "user", "content": req.message}],
) as stream:
for text in stream.text_stream:
yield text
return StreamingResponse(generate(), media_type="text/plain")Step 5
Run the server
Start your FastAPI server with Uvicorn.
bash
uvicorn main:app --reloadDone
You Are All Set
Your FastAPI application now compresses every OpenClaw prompt through claw.zip. This works with streaming, async, and all other FastAPI features.
More Guides