Anthropic
The @gensx/anthropic package provides a pre-wrapped version of the Anthropic SDK for GenSX, making it easy to use Anthropic’s API with GenSX functionality.
Installation
To install the package, run the following command:
npm install @gensx/anthropic @anthropic-ai/sdk
Usage
You can use this package in two ways:
1. Drop-in Replacement (Recommended)
Simply replace your Anthropic import with the GenSX version:
// Instead of:
// import { Anthropic } from '@anthropic-ai/sdk';
// Use:
import { Anthropic } from "@gensx/anthropic";
// Create a client as usual
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
// All methods are automatically wrapped with GenSX functionality
const completion = await client.messages.create({
model: "claude-sonnet-4-20250514",
messages: [{ role: "user", content: "Hello!" }],
max_tokens: 1000,
});
// Use streaming
const stream = await client.messages.create({
model: "claude-sonnet-4-20250514",
messages: [{ role: "user", content: "Hello!" }],
max_tokens: 1000,
stream: true,
});
2. Wrap an Existing Instance
If you already have an Anthropic instance, you can wrap it with GenSX functionality:
import { Anthropic } from "@anthropic-ai/sdk";
import { wrapAnthropic } from "@gensx/anthropic";
// Create your Anthropic instance as usual
const client = wrapAnthropic(
new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
}),
);
// Now all methods are wrapped with GenSX functionality
const completion = await client.messages.create({
model: "claude-sonnet-4-20250514",
messages: [{ role: "user", content: "Hello!" }],
max_tokens: 1000,
});
API Reference
The package exports:
Anthropic
- A drop-in replacement for the Anthropic client that automatically wraps all methods with GenSX functionalitywrapAnthropic
- A function to manually wrap an Anthropic instance with GenSX functionality
All methods from the Anthropic SDK are supported and automatically wrapped with GenSX functionality.
Last updated on