Skip to main content

Overview

The generate() method provides full control over text generation with customizable options and detailed performance metrics. Use this for production applications where you need fine-grained control.

Basic Usage

API Reference

Parameters

Returns

Generation Options

Temperature

Controls randomness in the output. Lower values make output more focused and deterministic.

Max Tokens

Limits the length of the generated response.

Stop Sequences

Stop generation when specific sequences are encountered.

System Prompts

Define the AI’s behavior and persona.
See System Prompts for more details.

Examples

Full Example with Metrics

React Hook

useGenerate.ts

Thinking Models

Some models support “thinking” or reasoning before responding:

Cancellation

Cancel an ongoing generation:

Chat

Simple one-liner interface

Streaming

Real-time token streaming

System Prompts

Control AI behavior

Best Practices

Optimization tips