Anthropic SDK Integration
Punk exposes an Anthropic-compatible Messages endpoint at /v1/messages. Point the official Anthropic TypeScript SDK at the Punk gateway origin and keep using messages.create(...) and streaming with Anthropic-shaped requests and responses.
Use this path when an app already uses Claude models or the Anthropic SDK and you want Punk to observe, govern, cache, explain, and learn from that traffic.
Install
npm install @anthropic-ai/sdk @punktechnologies/sdk
Create a Punk tenant API key in the hosted dashboard:
export PUNK_BASE_URL=https://app.punktechnologies.com
export PUNK_API_KEY=pk_...
Provider keys and BYOK credentials live in Punk's hosted control plane, not in this app.
Messages Setup
import Anthropic from "@anthropic-ai/sdk";
import { createPunkAnthropicConfig } from "@punktechnologies/sdk/anthropic";
const client = new Anthropic(createPunkAnthropicConfig({
app: "claude-app",
agent: "support-agent",
subject: "user-123"
}));
const message = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 256,
system: "You are a terse assistant.",
messages: [{ role: "user", content: "What is a deterministic artifact?" }]
});
console.log(message.content);
Add the Anthropic provider key in Punk's hosted dashboard or BYOK vault for live Claude pass-through.
For a zero-adapter SDK call, use the native Punk helper:
import { Punk } from "@punktechnologies/sdk";
const punk = new Punk({ app: "claude-app", agent: "support-agent", subject: "user-123" });
const message = await punk.anthropic.messages({
model: "claude-sonnet-4-6",
max_tokens: 256,
messages: [{ role: "user", content: "What is a deterministic artifact?" }]
});
console.log(message.content, message.route, message.runId, message.usage);
Read The Route
The Anthropic SDK exposes raw headers through .withResponse():
const { data, response } = await client.messages
.create({
model: "claude-sonnet-4-6",
max_tokens: 256,
messages: [{ role: "user", content: "Say hello." }]
})
.withResponse();
console.log(response.headers.get("x-punk-route"));
console.log(response.headers.get("x-punk-run-id"));
Inspect the route explanation in the dashboard or API:
curl -H "Authorization: Bearer $PUNK_API_KEY" \
https://app.punktechnologies.com/api/v1/runs/<runId> \
| jq .run.routeExplanation
Streaming
Anthropic streaming works through the same gateway origin:
const stream = client.messages.stream({
model: "claude-sonnet-4-6",
max_tokens: 256,
messages: [{ role: "user", content: "Stream a short haiku about caching." }]
});
for await (const event of stream) {
if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
process.stdout.write(event.delta.text);
}
}
Punk preserves Anthropic-shaped event sequences for live, cached, and artifact-served responses.
The Punk SDK also exposes parsed text deltas:
for await (const chunk of punk.streamMessages({
model: "claude-sonnet-4-6",
max_tokens: 256,
messages: [{ role: "user", content: "Stream a short haiku about caching." }]
})) {
if (chunk.type === "delta") process.stdout.write(chunk.content);
}
Read next: OpenAI-Compatible AI Gateway, Claude Code, SDK.