Skip to content

OpenAI

The OpenAI SDK covers GPT-4, GPT-4o, and the wider ecosystem of OpenAI-compatible endpoints. agentfootprint’s openai() factory wraps it as an LLMProvider — same shape as anthropic() and mock().

Terminal window
npm install openai

Peer 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' });

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.

provider.stream(req) uses the SDK’s native SSE streaming; tokens land as they arrive. Final chunk carries the full LLMResponse.

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.

  • Multi-modal not exposed yet (LLMMessage.content is string).
  • responseFormat (JSON-mode) not exposed yet — pass schema instructions via systemPrompt.
  • Resilience — wrap with withRetry / withFallback
  • Streaming — token-by-token UI rendering
  • Ollama — local models via OpenAI-compatible endpoint