OpenAI GPT Models
GPT (Generative Pre-trained Transformer) models are OpenAI's family of large language models that power applications from chatbots to code generation. They are the most widely used AI models for text generation, available through both the OpenAI API and the AI SDK.
Available GPT Models
Getting Started
Using the OpenAI SDK
import OpenAI from 'openai';
const openai = new OpenAI();
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain REST APIs in simple terms.' },
],
});
console.log(response.choices[0].message.content);
Using the AI SDK (Recommended for Next.js)
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
const { text } = await generateText({
model: openai('gpt-4o'),
prompt: 'Explain REST APIs in simple terms.',
});
Key Capabilities
- Text generation: Write, summarize, translate, and transform text
- Code generation: Write, explain, and debug code in any language
- Conversation: Multi-turn dialogue with context awareness
- Analysis: Process and analyze documents, data, and images
- Function calling: Invoke external tools and APIs based on natural language
- Vision: Analyze images when using multimodal models (GPT-4o, GPT-4 Turbo)
Important Parameters
Choosing the Right Model
- GPT-4o: Best default choice — fast, capable, and supports images
- GPT-4o Mini: Use when cost matters and the task is straightforward
- GPT-4 Turbo: Use for complex reasoning or when you need 128K context
Resources