Skip to main content

Basic Usage

The simplest way to generate text:

Input Formats

callModel accepts several input formats to match your use case.

String Input

The simplest format - a single string becomes a user message:

Message Array

For multi-turn conversations, pass an array of messages:

Multimodal

For rich content including images:

System Instructions

Set the model’s behavior with the instructions parameter:

Model Selection

Single Model

Specify a model by its OpenRouter ID:

Model Fallback

Provide multiple models for automatic fallback:
The SDK will try each model in order until one succeeds.

Response Methods

getText()

Returns just the text content after tool execution completes:

getResponse()

Returns the full response object including usage data:

Generation Parameters

Control the generation behavior:

Response Format

Request structured output:

Error Handling

Handle common error cases:

Concurrent Requests

Each callModel invocation is independent:

Next Steps

  • Streaming - Stream responses in real-time
  • Tools - Add tool capabilities to your generation
  • Message Formats - Convert from OpenAI/Claude formats