Skip to content

Anthropic (Node)

Behavior

  • Anthropic responses include usage.input_tokens and usage.output_tokens; no cost. Server computes cost using pricing registry (costSource="catalog").

Install

pnpm add @anthropic-ai/sdk

Minimal example

import Anthropic from '@anthropic-ai/sdk'
import { RunForge } from '../../sdk-ts/index'

const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY! })
const rf = new RunForge({ apiKey: process.env.RUNFORGE_API_KEY!, endpoint: process.env.RUNFORGE_ENDPOINT, projectId: process.env.RUNFORGE_PROJECT_ID })

await rf.track({ model: 'claude-3-5-sonnet-20241022', experiment: 'anthropic-demo' }, () =>
  client.messages.create({ model: 'claude-3-5-sonnet-20241022', max_tokens: 200, messages: [{ role: 'user', content: 'hi' }] })
)

Streaming

  • Stream responses and post one ingest event with final usage.

Troubleshooting

  • Keys: ANTHROPIC_API_KEY, RUNFORGE_API_KEY, RUNFORGE_PROJECT_ID.
  • Model names should match pricing registry keys or will be marked costEstimated=true.