Skip to content

OpenAI Provider

Set your OpenAI API key:

Terminal window
export OPENAI_API_KEY=sk-...

llmist will automatically discover and use OpenAI.

| Model | Alias | Best For | |-------|-------|----------| | gpt-5 | gpt5 | Complex reasoning, coding | | gpt-5-mini | gpt5-mini | Fast, cost-effective tasks | | gpt-4-turbo | gpt4-turbo | Balanced performance | | gpt-4o | gpt4o | Multimodal tasks | | o3 | o3 | Advanced reasoning Reasoning | | o4-mini | o4-mini | Fast reasoning Reasoning | | o3-mini | o3-mini | Compact reasoning |

| Model | Description | |-------|-------------| | dall-e-3 | High-quality image generation | | dall-e-2 | Faster, lower cost |

| Model | Description | |-------|-------------| | tts-1 | Text-to-speech, standard quality | | tts-1-hd | Text-to-speech, high quality |

import { LLMist } from 'llmist';
const answer = await LLMist.createAgent()
.withModel('gpt5')
.askAndCollect('Explain quantum computing');

OpenAI's o-series models (o3, o4-mini) and GPT-5 family support reasoning. llmist maps ReasoningEffort to OpenAI's native reasoning.effort parameter:

| Effort | OpenAI Value | |--------|-------------| | "none" | "none" | | "low" | "low" | | "medium" | "medium" | | "high" | "high" | | "maximum" | "xhigh" |

const answer = await LLMist.createAgent()
.withModel('o3')
.withReasoning('high')
.askAndCollect('Prove that √2 is irrational.');

See the Reasoning Models guide for full details.

GPT-4o and GPT-5 models support image input:

import { LLMist, imageFromUrl } from 'llmist';
const answer = await LLMist.createAgent()
.withModel('gpt4o')
.askWithImage(
'What is in this image?',
imageFromUrl('https://example.com/photo.jpg')
)
.askAndCollect();
import { LLMist, OpenAIChatProvider } from 'llmist';
const client = new LLMist({
autoDiscoverProviders: false,
adapters: [
new OpenAIChatProvider({
apiKey: process.env.OPENAI_API_KEY,
baseUrl: 'https://api.openai.com/v1', // Custom endpoint
organization: 'org-xxx', // Optional org ID
}),
],
});

llmist automatically tracks token usage and costs:

for await (const event of agent.run()) {
if (event.type === 'llm_call_complete') {
console.log('Tokens:', event.usage);
console.log('Cost:', event.cost);
}
}

OpenAI has rate limits. Use retry configuration for resilience:

const agent = LLMist.createAgent()
.withModel('gpt5')
.withRetry({
maxAttempts: 3,
retryOn: ['rate_limit', 'server_error'],
});