Get started with GPT-5
Get started with GPT-5 using the AI SDK.
With the release of OpenAI's GPT-5 model, there has never been a better time to start building AI applications with advanced capabilities like verbosity control, web search, and native multi-modal understanding.
The AI SDK is a powerful TypeScript toolkit for building AI applications with large language models (LLMs) like OpenAI GPT-5 alongside popular frameworks like React, Next.js, Vue, Svelte, Node.js, and more.
OpenAI GPT-5
OpenAI's GPT-5 represents their latest advancement in language models, offering powerful new features including verbosity control for tailored response lengths, integrated web search capabilities, reasoning summaries for transparency, and native support for text, images, audio, and PDFs. The model is available in three variants: gpt-5, gpt-5-mini for faster, more cost-effective processing, and gpt-5-nano for ultra-efficient operations.
Prompt Engineering for GPT-5
Here are the key strategies for effective prompting:
Core Principles
- Be precise and unambiguous: Avoid contradictory or ambiguous instructions. GPT-5 performs best with clear, explicit guidance.
- Use structured prompts: Leverage XML-like tags to organize different sections of your instructions for better clarity.
- Natural language works best: While being precise, write prompts as you would explain to a skilled colleague.
Prompting Techniques
1. Agentic Workflow Control
- Adjust the
reasoningEffortparameter to calibrate model autonomy - Set clear stop conditions and define explicit tool call budgets
- Provide guidance on exploration depth and persistence
2. Structured Prompt Format Use XML-like tags to organize your prompts:
3. Tool Calling Best Practices
- Use tool preambles to provide clear upfront plans
- Define safe vs. unsafe actions for different tools
- Create structured updates about tool call progress
4. Verbosity Control
- Use the
textVerbosityparameter to control response length programmatically - Override with natural language when needed for specific contexts
- Balance between conciseness and completeness
5. Optimization Workflow
- Start with a clear, simple prompt
- Test and identify areas of ambiguity or confusion
- Iteratively refine by removing contradictions
- Consider using OpenAI's Prompt Optimizer tool for complex prompts
- Document successful patterns for reuse
Getting Started with the AI SDK
The AI SDK is the TypeScript toolkit designed to help developers build AI-powered applications with React, Next.js, Vue, Svelte, Node.js, and more. Integrating LLMs into applications is complicated and heavily dependent on the specific model provider you use.
The AI SDK abstracts away the differences between model providers, eliminates boilerplate code for building chatbots, and allows you to go beyond text output to generate rich, interactive components.
At the center of the AI SDK is AI SDK Core, which provides a unified API to call any LLM. The code snippet below is all you need to call OpenAI GPT-5 with the AI SDK:
Generating Structured Data
While text generation can be useful, you might want to generate structured JSON data. For example, you might want to extract information from text, classify data, or generate synthetic data. AI SDK Core provides two functions (generateObject and streamObject) to generate structured data, allowing you to constrain model outputs to a specific schema.
This code snippet will generate a type-safe recipe that conforms to the specified zod schema.
Verbosity Control
One of GPT-5's new features is verbosity control, allowing you to adjust response length without modifying your prompt:
Web Search
GPT-5 can access real-time information through the integrated web search tool:
Reasoning Summaries
For transparency into GPT-5's thought process, enable reasoning summaries:
Using Tools with the AI SDK
GPT-5 supports tool calling out of the box, allowing it to interact with external systems and perform discrete tasks. Here's an example of using tool calling with the AI SDK:
Building Interactive Interfaces
AI SDK Core can be paired with AI SDK UI, another powerful component of the AI SDK, to streamline the process of building chat, completion, and assistant interfaces with popular frameworks like Next.js, Nuxt, and SvelteKit.
AI SDK UI provides robust abstractions that simplify the complex tasks of managing chat streams and UI updates on the frontend, enabling you to develop dynamic AI-driven interfaces more efficiently.
With four main hooks — useChat, useCompletion, and useObject — you can incorporate real-time chat capabilities, text completions, streamed JSON, and interactive assistant features into your app.
Let's explore building a chatbot with Next.js, the AI SDK, and OpenAI GPT-5:
In a new Next.js application, first install the AI SDK and the OpenAI provider:
$ pnpm install ai @ai-sdk/openai @ai-sdk/react
Then, create a route handler for the chat endpoint:
Finally, update the root page (app/page.tsx) to use the useChat hook:
The useChat hook on your root page (app/page.tsx) will make a request to your AI provider endpoint (app/api/chat/route.ts) whenever the user submits a message. The messages are then displayed in the chat UI.
Get Started
Ready to get started? Here's how you can dive in:
- Explore the documentation at ai-sdk.dev/docs to understand the full capabilities of the AI SDK.
- Check out practical examples at ai-sdk.dev/cookbook to see the SDK in action and get inspired for your own projects.
- Dive deeper with advanced guides on topics like Retrieval-Augmented Generation (RAG) and multi-modal chat at ai-sdk.dev/cookbook/guides.
- Check out ready-to-deploy AI templates at vercel.com/templates?type=ai.