Skip to content

OpenAI Provider

Set your OpenAI API key:

Terminal window
export OPENAI_API_KEY=sk-...

llmist will automatically discover and use OpenAI.

ModelAliasBest For
gpt-5gpt5Complex reasoning, coding
gpt-5-minigpt5-miniFast, cost-effective tasks
gpt-4-turbogpt4-turboBalanced performance
gpt-4ogpt4oMultimodal tasks
o3-minio3-miniReasoning tasks
ModelDescription
dall-e-3High-quality image generation
dall-e-2Faster, lower cost
ModelDescription
tts-1Text-to-speech, standard quality
tts-1-hdText-to-speech, high quality
import { LLMist } from 'llmist';
const answer = await LLMist.createAgent()
.withModel('gpt5')
.askAndCollect('Explain quantum computing');

GPT-4o and GPT-4 Turbo 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'],
});