Back to Guides

Anthropic Node.js

Official Anthropic SDK for Node.js and TypeScript

TypeScripteasy

The Anthropic Node.js SDK provides access to Claude models. Decyra's proxy captures all Anthropic API calls, enabling observability and control over your Claude interactions.

Prerequisites

  • Decyra account with API key
  • Node.js 18+ installed
  • @anthropic-ai/sdk package installed

Installation

npm install @anthropic-ai/sdk @decyra/sdk

Integration

Wrap the fetch function to route through Decyra:

import Anthropic from '@anthropic-ai/sdk';
import { wrapFetch } from '@decyra/sdk';

const customFetch = wrapFetch(fetch, {
  baseURL: 'https://proxy.decyra.com',
  apiKey: process.env.DECYRA_API_KEY!,
});

const anthropic = new Anthropic({
  apiKey: process.env.DECYRA_API_KEY!,
  fetch: customFetch,
});

Use the client for messages:

const message = await anthropic.messages.create({
  model: 'claude-3-opus-20240229',
  max_tokens: 1024,
  messages: [
    { role: 'user', content: 'Explain the theory of relativity' }
  ],
});

console.log(message.content[0].text);

What Gets Captured

FieldDescription
ModelClaude model identifier
Max TokensMaximum tokens in response
MessagesArray of conversation messages
Prompt HashHash of the input prompt
Response TimeTime for API call
Token UsageInput/output token counts
CostEstimated cost per request
Stop SequencesStop sequence configuration

Verify

Check your Decyra dashboard to see Anthropic API calls in the traces view. Each message creation will appear with full details.

Next Steps