@hashbrownai/anthropic
v0.5.0
Published
Anthropic provider for Hashbrown AI
Readme
Getting Started
Installation
npm install @hashbrownai/anthropic --saveYou'll also need to install the Anthropic SDK as a peer dependency:
npm install @anthropic-ai/sdk --saveBasic Usage
Deploy an express server with a single /chat endpoint to use Hashbrown with Anthropic.
import { HashbrownAnthropic } from '@hashbrownai/anthropic';
app.post('/chat', async (req, res) => {
const stream = HashbrownAnthropic.stream.text({
apiKey: process.env.ANTHROPIC_API_KEY!,
request: req.body, // must be Chat.Api.CompletionCreateParams
});
res.header('Content-Type', 'application/octet-stream');
for await (const chunk of stream) {
res.write(chunk); // Pipe each encoded frame as it arrives
}
res.end();
});Advanced Usage with Custom Base URL
import { HashbrownAnthropic } from '@hashbrownai/anthropic';
const stream = HashbrownAnthropic.stream.text({
apiKey: process.env.ANTHROPIC_API_KEY!,
baseURL: 'https://api.anthropic.com', // Optional custom base URL
request: {
model: process.env.ANTHROPIC_MODEL ?? 'claude-haiku-4-5-20251001',
system: 'You are a helpful assistant.',
messages: [
{
role: 'user',
content: 'Hello, how are you?',
},
],
// Optional: Add tools for function calling
tools: [
{
name: 'get_weather',
description: 'Get the current weather for a location',
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
},
required: ['location'],
},
},
],
toolChoice: 'auto',
// Optional: Add structured output schema
responseFormat: {
type: 'object',
properties: {
answer: { type: 'string' },
confidence: { type: 'number' },
},
required: ['answer'],
},
},
// Optional: Transform request options before sending to Anthropic
transformRequestOptions: (options) => {
// Modify options as needed
return {
...options,
max_tokens: 1000, // Override max tokens
};
},
});API Reference
HashbrownAnthropic.stream.text(options)
Creates a streaming text completion using Anthropic's Claude models.
Parameters
options.apiKey(string, required): Your Anthropic API keyoptions.baseURL(string, optional): Custom base URL for Anthropic APIoptions.request(Chat.Api.CompletionCreateParams, required): The completion request parametersoptions.transformRequestOptions(function, optional): Function to modify request options before sending
Returns
An async iterable that yields Uint8Array chunks encoded with Hashbrown's frame protocol.
Supported Features
- ✅ Text Streaming: Real-time streaming of text completions
- ✅ Tool Calling: Function calling with automatic tool execution
- ✅ Structured Output: JSON schema validation for responses
- ✅ System Messages: Custom system prompts and instructions
- ✅ Message History: Full conversation context support
- ✅ Error Handling: Proper error propagation through the stream
Models
The adapter supports all Anthropic Claude models. We currently recommend using
claude-haiku-4-5-20251001, which is widely available for streaming and tool
calling. Switch to newer releases by setting the ANTHROPIC_MODEL environment
variable.
Docs
Read the docs for the Hashbrown Anthropic adapter.
Contributing
hashbrown is a community-driven project. Read our contributing guidelines on how to get involved.
Workshops and Consulting
Want to learn how to build web apps with AI? Learn more about our workshops.
LiveLoveApp provides hands-on engagement with our AI engineers for architecture reviews, custom integrations, proof-of-concept builds, performance tuning, and expert guidance on best practices. Learn more about LiveLoveApp.
License
MIT © LiveLoveApp, LLC
