---
title: generateText
description: API Reference for generateText.
url: "https://ai-sdk.dev/docs/reference/ai-sdk-core/generate-text"
docs_index: /llms.txt
---

> For an index of all documentation, see [/llms.txt](/llms.txt).

Generates text and calls tools for a given prompt using a language model.

It is ideal for non-interactive use cases such as automation tasks where you need to write text (e.g. drafting email or summarizing web pages) and for agents that use tools.

```ts
import { generateText } from 'ai';

const { text } = await generateText({
  model: "anthropic/claude-sonnet-5.5",
  prompt: 'Invent a new holiday and describe its traditions.',
});

console.log(text);
```

For guidance on `runtimeContext`, `toolsContext`, tool `context`, and sensitive
context filtering, see [Runtime and Tool
Context](/docs/ai-sdk-core/runtime-and-tool-context).

To see `generateText` in action, check out [these examples](#examples).

## Import

## API Signature

### Parameters

### Returns

## Types

### `ActiveTools`

```ts
type ActiveTools<TOOLS extends ToolSet> =
  | ReadonlyArray<keyof TOOLS & string>
  | undefined;
```

Limits a generation step to the listed tool names. `undefined` means no tool restriction is applied.

## Examples

---

For a semantic overview of all documentation, see [/sitemap.md](/sitemap.md)

For an index of all available documentation, see [/llms.txt](/llms.txt)

For agent-facing discovery, including API and MCP surfaces, see [/agents.md](/agents.md)