OpenAI
The OpenAI SDK covers GPT-4, GPT-4o, and the wider ecosystem of OpenAI-compatible endpoints. agentfootprint’s
openai()factory wraps it as anLLMProvider— same shape asanthropic()andmock().
Install
Section titled “Install”npm install openaiPeer dep, lazy-required, optional in peerDependenciesMeta. Friendly install hint at first call if missing.
import { Agent, openai } from 'agentfootprint';
const provider = openai({ apiKey: process.env.OPENAI_API_KEY!,});
const agent = Agent.create({ provider, model: 'gpt-4o',}).build();OpenAI-compatible endpoints (Ollama, Together, Groq, vLLM, LM Studio)
Section titled “OpenAI-compatible endpoints (Ollama, Together, Groq, vLLM, LM Studio)”The baseURL option points the SDK at any OpenAI-compatible endpoint. No separate adapter needed:
const provider = openai({ apiKey: 'not-needed-for-local', baseURL: 'http://localhost:11434/v1', // Ollama});
// Or:const groq = openai({ apiKey: process.env.GROQ_API_KEY!, baseURL: 'https://api.groq.com/openai/v1',});For Ollama specifically, the convenience factory:
import { ollama } from 'agentfootprint';
const provider = ollama({ model: 'llama3.1' });Tools (function calling)
Section titled “Tools (function calling)”OpenAI’s Chat Completions API has native function calling. The provider translates Tool[] into the API’s tools format and round-trips assistant tool_calls.
Streaming
Section titled “Streaming”provider.stream(req) uses the SDK’s native SSE streaming; tokens land as they arrive. Final chunk carries the full LLMResponse.
Browser variant
Section titled “Browser variant”BrowserOpenAIProvider — fetch-based, zero peer deps. CORS depends on the endpoint; OpenAI requires the user-supplied key in the Authorization header, which the consumer must set explicitly.
Limitations
Section titled “Limitations”- Multi-modal not exposed yet (
LLMMessage.contentisstring). responseFormat(JSON-mode) not exposed yet — pass schema instructions viasystemPrompt.
Next steps
Section titled “Next steps”- Resilience — wrap with
withRetry/withFallback - Streaming — token-by-token UI rendering
- Ollama — local models via OpenAI-compatible endpoint