OpenAI
openai() — GPT provider via the openai SDK. Also covers OpenAI-compatible endpoints (Together, Groq, vLLM, LM Studio) via baseURL.
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
npm install openaiPeer dep, lazy-required, optional in peerDependenciesMeta. Friendly install hint at first call if missing.
Use
openai() is a vendor-SDK provider, so it lives at the agentfootprint/llm-providers subpath (this keeps the lazy openai peer-dep require out of the main barrel). Agent comes from the main barrel as usual:
import { Agent } from 'agentfootprint';
import { openai } from 'agentfootprint/llm-providers';
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)
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 (also from agentfootprint/llm-providers). It defaults baseURL to http://localhost:11434/v1 and names the provider ollama; set the model via defaultModel (or pass a custom host):
import { ollama } from 'agentfootprint/llm-providers';
const provider = ollama({ defaultModel: 'llama3.1' });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
provider.stream(req) uses the SDK's native SSE streaming; tokens land as they arrive. Final chunk carries the full LLMResponse.
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
- Multi-modal not exposed yet (
LLMMessage.contentisstring). responseFormat(JSON-mode) not exposed yet — pass schema instructions viasystemPrompt.
Next steps
- Resilience — wrap with
withRetry/withFallback - Streaming — token-by-token UI rendering
- Ollama — local models via OpenAI-compatible endpoint
