Foundations: Prompts

ID: 1606https://ai-sdk.dev/docs/ai-sdk-core/prompts
Source

Prompts

Prompts are instructions that you give a large language model (LLM) to tell it what to do.
It’s like when you ask someone for directions; the clearer your question, the better the directions you’ll get.

Many LLM providers offer complex interfaces for specifying prompts. They involve different roles and message types.
While these interfaces are powerful, they can be hard to use and understand.

In order to simplify prompting, the AI SDK supports text, message, and system prompts.

Text Prompts

Text prompts are strings.
They are ideal for simple generation use cases, e.g. repeatedly generating content for variants of the same prompt text.

You can set text prompts using the prompt property made available by AI SDK functions like streamText or generateObject.
You can structure the text in any way and inject variables, e.g. using a template literal.

const result = await generateText({
  model: 'openai/gpt-4.1',
  prompt: 'Invent a new holiday and describe its traditions.',
});

You can also use template literals to provide dynamic data to your prompt.

const result = await generateText({
  model: 'openai/gpt-4.1',
  prompt:
    `I am planning a trip to ${destination} for ${lengthOfStay} days. ` +
    `Please suggest the best tourist activities for me to do.`
});

System Prompts

System prompts are the initial set of instructions given to models that help guide and constrain the models’ behaviors and responses.
You can set system prompts using the system property.
System prompts work with both the prompt and the messages properties.

const result = await generateText({
  model: 'openai/gpt-4.1',
  system:
    `You help planning travel itineraries. ` +
    `Respond to the users' request with a list ` +
    `of the best stops to make in their destination.`,
  prompt:
    `I am planning a trip to ${destination} for ${lengthOfStay} days. ` +
    `Please suggest the best tourist activities for me to do.`
});

Note
When you use a message prompt, you can also use system messages instead of a system prompt.

Message Prompts

A message prompt is an array of user, assistant, and tool messages.
They are great for chat interfaces and more complex, multi‑modal prompts.
You can use the messages property to set message prompts.

Each message has a role and a content property.
The content can either be text (for user and assistant messages), or an array of relevant parts (data) for that message type.

const result = await generateText({
  model: 'openai/gpt-4.1',
  messages: [
    { role: 'user', content: 'Hi!' },
    { role: 'assistant', content: 'Hello, how can I help?' },
    { role: 'user', content: 'Where can I buy the best Currywurst in Berlin?' }
  ],
});

Instead of sending a text in the content property, you can send an array of parts that includes a mix of text and other content parts.

⚠️ Warning
Not all language models support all message and content types.
For example, some models might not be capable of handling multi‑modal inputs or tool messages.
Learn more about the capabilities of select models.

Provider Options

(Further content continues here…)