Using claw.zip with Next.js
Next.js is one of the most popular frameworks for building AI-powered applications. Integrating claw.zip takes under a minute and immediately reduces your OpenClaw API costs. This guide is especially valuable if you are already an OpenClaw user β you will be compressing prompts and routing intelligently with zero code refactoring.
Before You Start
Prerequisites
- βA Next.js project with AI features
- βAn OpenClaw API key
- βA claw.zip account and API key
Step-by-Step
Integration Steps
Install the Anthropic SDK
If you haven't already, install the official Anthropic SDK for Node.js.
npm install @anthropic-ai/sdkSet your environment variables
Add your claw.zip API key and OpenClaw key to your .env.local file.
# .env.local
CLAWZIP_API_KEY=your_clawzip_key_here
ANTHROPIC_API_KEY=your_openclaw_key_hereConfigure the Anthropic client
Change the base URL from api.anthropic.com to api.claw.zip. That is the only code change needed.
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
baseURL: 'https://api.claw.zip',
defaultHeaders: {
'x-api-key': process.env.CLAWZIP_API_KEY,
},
});Use in your API route
Use the configured client in a Next.js API route or Server Action. All requests are automatically compressed.
// app/api/chat/route.ts
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const { message } = await req.json();
const response = await client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{ role: 'user', content: message }],
});
return NextResponse.json(response);
}Verify compression
Check the response headers to see compression stats. The x-compression-ratio header shows how much your prompt was compressed.
// The response includes compression metadata:
// x-compression-ratio: 0.22 (78% reduction)
// x-tokens-saved: 847
// x-model-used: claude-sonnet-4-20250514Done
You Are All Set
Your Next.js application is now using claw.zip. Every OpenClaw API call will be automatically compressed, saving you 80-93% on token costs with no changes to your application logic.
More Guides