Skip to content

OpenAI

Terminal window
npm install agentfootprint openai
import { Agent, openai, defineTool } from 'agentfootprint';
const provider = openai('gpt-4o', {
apiKey: process.env.OPENAI_API_KEY,
});
const agent = Agent.create({ provider })
.system('You are a helpful assistant.')
.tool(myTool)
.streaming(true)
.build();
const result = await agent.run('Hello');

No SDK dependency — calls the OpenAI REST API directly:

import { Agent, BrowserOpenAIAdapter } from 'agentfootprint';
const provider = new BrowserOpenAIAdapter({
apiKey: userApiKey,
model: 'gpt-4o',
});
const agent = Agent.create({ provider }).build();
ModelIDBest for
GPT-4ogpt-4oGeneral purpose
GPT-4o Minigpt-4o-miniFast, low cost
GPT-4.1gpt-4.1Coding, instruction following
GPT-4.1 Minigpt-4.1-miniBudget coding
GPT-4.1 Nanogpt-4.1-nanoFastest, cheapest
o3o3Complex reasoning
o3 Minio3-miniFast reasoning
o4 Minio4-miniLatest reasoning
import OpenAI from 'openai';
const client = new OpenAI();
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(response.choices[0].message.content);

Track tokens, cost, and tool usage:

import { Agent, openai } from 'agentfootprint';
import { agentObservability } from 'agentfootprint/observe';
const obs = agentObservability();
const agent = Agent.create({
provider: openai('gpt-4o'),
})
.system('You are helpful.')
.recorder(obs)
.build();
await agent.run('Hello');
console.log(obs.tokens()); // { totalCalls: 1, totalInputTokens: 18, ... }
console.log(obs.cost()); // USD estimate

Cross-provider resilience — the order is configurable:

import { anthropic, openai } from 'agentfootprint';
import { fallbackProvider } from 'agentfootprint/resilience';
// OpenAI primary, Claude fallback
const provider = fallbackProvider([
openai('gpt-4o'),
anthropic('claude-sonnet-4-20250514'),
]);
// Or Claude primary, OpenAI fallback — swap the order
const provider = fallbackProvider([
anthropic('claude-sonnet-4-20250514'),
openai('gpt-4o'),
]);

What you gain: Same agent code works across providers. Swap one line to switch. Add fallback for resilience.