TypeScript / Node.js Integration
Use ANT with the OpenAI SDK, Anthropic SDK, or native fetch.
OpenAI SDK (Recommended)
Install the SDK:
npm install openai
# or
pnpm add openaiBasic Usage
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://antbase.ai/v1',
apiKey: process.env.ANT_API_KEY,
});
async function main() {
const response = await client.chat.completions.create({
model: 'ant:auto',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain async/await in JavaScript.' },
],
});
console.log(response.choices[0].message.content);
}
main();Streaming
const stream = await client.chat.completions.create({
model: 'ant:auto',
messages: [{ role: 'user', content: 'Write a haiku about TypeScript.' }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) {
process.stdout.write(content);
}
}With Tools (Function Calling)
const response = await client.chat.completions.create({
model: 'ant:auto',
messages: [{ role: 'user', content: 'What is the weather in Tokyo?' }],
tools: [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get current weather for a location',
parameters: {
type: 'object',
properties: {
location: { type: 'string' },
},
required: ['location'],
},
},
},
],
});
if (response.choices[0].message.tool_calls) {
console.log('Tool calls:', response.choices[0].message.tool_calls);
}Edge & Serverless
ANT works great with edge functions and serverless environments:
// Vercel Edge Function
import OpenAI from 'openai';
export const runtime = 'edge';
export async function POST(request: Request) {
const client = new OpenAI({
baseURL: 'https://antbase.ai/v1',
apiKey: process.env.ANT_API_KEY,
});
const { messages } = await request.json();
const stream = await client.chat.completions.create({
model: 'ant:fast', // Fast for edge
messages,
stream: true,
});
// Return streaming response
return new Response(stream.toReadableStream(), {
headers: { 'Content-Type': 'text/event-stream' },
});
}Deno
The OpenAI SDK also works with Deno:
import OpenAI from 'npm:openai';
const client = new OpenAI({
baseURL: 'https://antbase.ai/v1',
apiKey: Deno.env.get('ANT_API_KEY'),
});
const response = await client.chat.completions.create({
model: 'ant:auto',
messages: [{ role: 'user', content: 'Hello from Deno!' }],
});
console.log(response.choices[0].message.content);