Node.js

The official openai and anthropic Node.js clients.

The official openai and @anthropic-ai/sdk packages work with a base URL change.

shell
npm install openai @anthropic-ai/sdk

Chat

typescript
import OpenAI from 'openai';

const client = new OpenAI({ apiKey: process.env.TB_API_KEY, baseURL: 'https://api.topbilling.in/v1' });
const resp = await client.chat.completions.create({ model: '<model-id>', messages: [{ role: 'user', content: 'Hello from Node' }] });
console.log(resp.choices[0].message.content);

Streaming

typescript
const stream = await client.chat.completions.create({ model: '<model-id>', messages, stream: true });
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");

Messages

typescript
import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({ apiKey: process.env.TB_API_KEY, baseURL: 'https://api.topbilling.in' });
const msg = await anthropic.messages.create({ model: '<model-id>', max_tokens: 256, messages: [{ role: 'user', content: 'Hello' }] });