Generations API (TypeScript)

Methods, examples, and parameters for client.generations.

Module Overview

Legacy and lightweight text generation endpoints for completion-style requests.

Available Methods

  • client.generations.create() - Create a text generation.
  • client.generations.stream() - Stream token deltas.
  • client.generations.cancel() - Cancel an in-flight generation.

Examples

TypeScript
import { TheRouter.ai } from "@therouter/sdk";

const client = new TheRouter.ai({ apiKey: process.env.THEROUTER_API_KEY! });

const gen = await client.generations.create({
  model: "openai/gpt-4o-mini",
  prompt: "Write a one-line changelog entry.",
  max_tokens: 80,
});

console.log(gen.output_text);
generations-response.json
{
  "id": "req_01HXYZ123",
  "module": "generations",
  "status": "ok"
}

Parameter Types

NameTypeRequiredDescription
model
stringRequiredModel identifier to use.
prompt
stringRequiredPlain text prompt.
max_tokens
integerMaximum generated tokens.
SDK parity
Method signatures are aligned across SDKs so migration between TypeScript and Python stays predictable.