Generations API (Python)

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

Python
from therouter import TheRouter.ai

client = TheRouter.ai(
    api_key=os.getenv("THEROUTER_API_KEY"),
    base_url="https://api.therouter.ai/v1",
)

generation = client.generations.create(
    model="openai/gpt-4o-mini",
    prompt="Write a one-line changelog entry.",
    max_tokens=80,
)

print(generation.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.