> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runanywhere.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# generate()

> One-shot text generation

```ts theme={"theme":"css-variables"}
const result = await RunAnywhere.llm.generate('Name three colours')
console.log(result.text)
```

## Signature

One method takes either a prompt or a conversation:

```ts theme={"theme":"css-variables"}
generate(
  input: string | readonly ChatMessage[],
  options?: LlmOptions
): Promise<GenerationResult>
```

This differs from Swift and Kotlin, which have two overloads. On Web there is one method and a
union input.

## With options

```ts theme={"theme":"css-variables"}
const result = await RunAnywhere.llm.generate('Explain quantum computing', {
  model: 'qwen3-0.6b',
  maxOutputTokens: 200,
  temperature: 0.7,
})

console.log(result.text, result.tokensPerSecond)
```

Generation auto-loads what it needs, and downloads when `options.model` names a model that is
absent.

## LlmOptions

| Field | Type | Default |
| - | - | - |
| `model` | `string` | none; uses the loaded model |
| `maxOutputTokens` | `number` | proto default |
| `temperature` | `number` | proto default |
| `topP` | `number` | proto default |
| `systemPrompt` | `string` | none |
| `stopSequences` | `string[]` | `[]` |
| `reasoning` | `ReasoningOptions` | none |
| `tools` | `ToolDefinition[]` | `[]` |
| `toolChoice` | `ToolChoice` | `auto` |
| `maxToolCalls` | `number` | `5` |

## Structured output

```ts theme={"theme":"css-variables"}
const result = await RunAnywhere.llm.generateStructured(
  'Extract the name and age: Dana is 34.',
  schema,
  'validationOnly'
)
```

| Mode | Behaviour |
| - | - |
| `'validationOnly'` | Generate freely, then validate. The default. |
| `'repair'` | Validate, then retry once with a repair instruction. |
| `'constrained'` | **Throws today.** |

## Errors

Throws `SDKException` when no model can be loaded or generation fails. See
[Error handling](https://docs.runanywhere.ai/web/error-handling.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.