Learning resourcesReviewed · OpenRouter

OpenRouter Agent SDK: Text Generation

OpenRouter’s Text Generation guide is a reference for developers adding AI responses to applications, but it assumes API access and omits installation and pricing details. It covers TypeScript and Python SDK calls alongside direct HTTP examples in Go and cURL.

Researched 23 Nov 2026

In short.

OpenRouter’s Text Generation guide is a practical reference for developers building AI features, but it leaves package compatibility, current costs and production reliability unresolved. It documents text and image inputs, conversation history, model fallback, JSON output, usage inspection and concurrent requests. Its printed outputs illustrate intended behavior without establishing runtime correctness or performance.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage is limited to the complete supplied page at [https://openrouter.ai/docs/agent-sdk/call-model/text-generation.md], including all language examples and printed outputs. The documentation-index notice and links to streaming, tools and message formats are present, but their destinations are excluded. Package repositories, installation documentation, pricing and legal terms are outside this scope. No code was executed, and runtime correctness, performance and reliability remain unassessed.

The overview

Identity

This is OpenRouter’s Text Generation documentation page at [https://openrouter.ai/docs/agent-sdk/call-model/text-generation.md]. It teaches callModel in TypeScript and call_model in Python, with Go and cURL examples that call the Responses API directly.

The resource is a programming guide. The referenced SDK packages and hosted API are components used by its examples.

Assessment

Based on its coverage, the guide is useful when you already have API access and need to construct requests or retrieve responses. It gives concrete examples across four implementation approaches.

It is less self-contained for a first integration: installation commands, runtime requirements and pinned package versions are absent. Runtime correctness and reliability have not been assessed.

Users

Beginner developers can learn the progression from a single prompt to conversation messages and JSON output. Following the examples requires familiarity with environment variables and asynchronous programming or HTTP requests.

Experienced developers can use the request fields, response accessors, fallback configuration and concurrency examples as integration references. Go users receive direct HTTP examples rather than a demonstrated Go Agent SDK.

Capabilities

The page demonstrates string prompts, arrays of conversation messages, image inputs supplied by URL, and an instructions parameter for directing model behavior. Conversation examples explicitly include previous messages in each request.

It also covers choosing one model or an ordered fallback list, setting temperature and output limits, requesting JSON objects, retrieving usage information, recognizing common HTTP errors and issuing independent requests concurrently.

Using it

Requirements

The examples require an OpenRouter API key supplied through OPENROUTER_API_KEY and network access to OpenRouter. The TypeScript examples reference @openrouter/agent and, in some sections, @openrouter/sdk. Python examples import openrouter_agent.

Go examples use standard HTTP and JSON packages. The cURL examples use shell commands and jq to extract output. Minimum runtime versions, package versions and model access requirements are unspecified.

Mechanism

SDK calls produce a result object. Awaiting getText() or get_text() retrieves generated text; getResponse() or get_response() retrieves the full response and usage information. The page states that text retrieval waits for tool execution to finish, although tool configuration is outside this page.

Direct HTTP examples post JSON to [https://openrouter.ai/api/v1/responses] with bearer authentication, then extract output_text content from message items. For fallback, the page says models are tried in listed order until one succeeds; it does not explain which failures trigger another attempt.

Setup

The documented sequence is to provide the API key, initialize the client, choose a model and input, and await the desired response accessor. Direct HTTP requests also set the Authorization and Content-Type headers.

Most TypeScript examples import OpenRouter from @openrouter/agent, while the generation-parameter and concurrency examples import it from @openrouter/sdk. The page does not explain the relationship or compatible versions of those packages. It also shows both callModel(openrouter, options) and openrouter.callModel(options).

Example

The basic example sends a one-sentence quantum-computing explanation request to openai/gpt-5-nano and retrieves the text through the SDK accessor. A conversation example sends earlier user and assistant messages before asking the model to recall the user’s name.

For application-readable output, another example requests three programming languages with text.format.type set to json_object, then parses the returned text as JSON. This demonstrates requesting and parsing an object; it does not establish validation against a particular schema.

Assessment & evidence

Limitations

Streaming, tool configuration and message-format conversion are linked topics without implementation guidance on this page. The image example does not establish image support across all models, and JSON object mode does not demonstrate schema enforcement.

The error examples recognize authentication, rate-limit and availability errors, including HTTP 401, 429 and 503. They do not implement a retry policy, backoff or explicit request timeouts. Rate limits, model-feature compatibility and data-retention behavior remain unknown.

Reasoning

The guide’s practical value comes from showing how input construction, model choice and response retrieval fit together. Its explicit conversation history and full-response examples help explain what an application sends and what it receives.

The breadth of examples supports using it as an implementation reference. Missing installation details and operational guarantees limit what can be concluded about deployment effort or suitability for a particular workload.

Alternatives

The page offers SDK helpers in TypeScript and Python or direct HTTP requests in Go and cURL. The SDK examples provide text and full-response accessors; the HTTP examples explicitly construct requests and extract response content.

These are different ways to access the same service. The evidence provides no comparative assessment of other services or libraries.

Evidence

The evidence consists of the complete supplied Text Generation page, including its request examples, explanatory prose and printed outputs. Those outputs illustrate documented behavior; they do not establish repeatability, accuracy, latency or successful error recovery.

No examples were executed. Compatibility and runtime behavior remain unassessed.

Access & freshness

Costs

Current costs are unknown from this page. A printed response includes token counts and a cost field, but that individual example does not establish a price schedule, currency, account fees or a budget for another workload.

The response methods expose usage information that may help track consumption. The page does not quantify spending for fallback attempts or concurrent requests.

Rights

The supplied page does not state licences for its prose, code examples or referenced SDK packages. Permission to redistribute those materials is therefore unknown from this evidence.

Generated-output ownership, service terms and data-handling rights are also unspecified.

Freshness

The supplied page was captured on 23 November 2026 at 05:33:03.181 UTC. It states no publication date, update date or SDK release number.

Model identifiers such as openai/gpt-5-nano and anthropic/claude-sonnet-4.5 appear as examples. Their current availability and compatibility with every demonstrated feature are not established by the page alone.

Actions

Before adopting a snippet, confirm the required package versions, client imports, model availability and current prices. Choose whether your application needs plain text or the full response with usage information.

For JSON output, add validation appropriate to the consuming application. Before using fallback or concurrency, define error handling, request timeouts and spending limits; the examples leave those decisions to the developer.

Evidence for this report

selected-page.txtselected · checked 2026-11-23