> ## 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.

# Simple Generation

> Quick text generation with minimal setup

<Note>**Early Beta** -- The Web SDK is in early beta. APIs may change between releases.</Note>

## Overview

The `TextGeneration.generate()` method with default options provides the simplest way to generate text. For a one-line approach, just pass a prompt and get a result.

## Basic Usage

```typescript theme={null}
import { TextGeneration } from '@runanywhere/web'

const result = await TextGeneration.generate('What is the capital of France?')
console.log(result.text) // "Paris is the capital of France."
```

## API Reference

```typescript theme={null}
await TextGeneration.generate(
  prompt: string,
  options?: LLMGenerationOptions
): Promise<LLMGenerationResult>
```

### Parameters

| Parameter | Type                   | Description                    |
| --------- | ---------------------- | ------------------------------ |
| `prompt`  | `string`               | The user's message or question |
| `options` | `LLMGenerationOptions` | Optional generation settings   |

### Returns

| Type                           | Description                              |
| ------------------------------ | ---------------------------------------- |
| `Promise<LLMGenerationResult>` | Result with text and performance metrics |

### Throws

| Error Code         | Description         |
| ------------------ | ------------------- |
| `NotInitialized`   | SDK not initialized |
| `ModelNotLoaded`   | No LLM model loaded |
| `GenerationFailed` | Generation failed   |

## Examples

### Simple Q\&A

```typescript theme={null}
const capital = await TextGeneration.generate('What is the capital of Japan?')
// capital.text: "Tokyo is the capital of Japan."

const math = await TextGeneration.generate('Calculate 15% of 200')
// math.text: "15% of 200 is 30."
```

### With Options

```typescript theme={null}
const result = await TextGeneration.generate('Write a haiku about coding', {
  maxTokens: 50,
  temperature: 0.8,
})

console.log(result.text)
console.log(`${result.tokensPerSecond.toFixed(1)} tok/s | ${result.latencyMs}ms`)
```

### Error Handling

```typescript theme={null}
import { TextGeneration, SDKError, SDKErrorCode } from '@runanywhere/web'

try {
  const result = await TextGeneration.generate('Hello')
} catch (err) {
  if (err instanceof SDKError) {
    switch (err.code) {
      case SDKErrorCode.NotInitialized:
        console.error('Initialize the SDK first')
        break
      case SDKErrorCode.ModelNotLoaded:
        console.error('Load a model first')
        break
      default:
        console.error(`SDK error [${err.code}]: ${err.message}`)
    }
  }
}
```

## Simple vs Full Generation

| Feature       | Simple (defaults)     | Full (`generate()` with options) |
| ------------- | --------------------- | -------------------------------- |
| Return type   | `LLMGenerationResult` | `LLMGenerationResult`            |
| Metrics       | Yes                   | Yes                              |
| Options       | Defaults              | Customizable                     |
| System prompt | None                  | Yes                              |
| Use case      | Quick prototyping     | Production apps                  |

<Tip>
  For quick prototyping, use `generate()` with just a prompt. Switch to adding options when you need
  custom temperature, system prompts, or token limits.
</Tip>

## Related

<CardGroup cols={2}>
  <Card title="Generate" icon="wand-magic-sparkles" href="/web/llm/generate">
    Full generation with options and metrics
  </Card>

  <Card title="Streaming" icon="water" href="/web/llm/stream">
    Real-time token streaming
  </Card>
</CardGroup>
