The runtime injects a configured model into your script's scope — it's the OpenRouter-backed pydantic-ai chat model, already authenticated. The smallest call:
from pydantic_ai import Agent
result = Agent(model).run_sync("Reply with a single word: hello")
print(result.output)Agent(model) wraps the model. .run_sync(prompt) blocks until done. .output is the string?
Exactly. The result object also carries token counts, tool calls, timing — but for a plain answer, .output is the field you read. Real LLM, real response, real cost (one quota slot per call).
Agent(model).run_sync(prompt).outputThe runtime hands you model ready-made. Three lines to call:
from pydantic_ai import Agent
result = Agent(model).run_sync("your prompt")
print(result.output)| In your scope | Source |
|---|---|
model | runtime injection (OpenRouter-routed, your per-user key, ready to use) |
Agent | imported from pydantic_ai |
OpenAIChatModel, OpenAIProvider | imported from pydantic_ai.models.openai if you need them (rarely — the runtime sets up model already) |
No API key handling. No provider config. The platform proxy meters per-call and uses your per-user OpenRouter key under the hood.
.run_sync vs .run.run_sync(prompt) — blocks the script until the response arrives. What you'll use 99% of the time in lessons..run(prompt) — async version, requires await. Used in async pipelines.result = Agent(model).run_sync(...) returns an object with at least:
.output — the model's text response.usage() — token counts (next time).all_messages() — the full message history (multi-turn lesson)For a plain-text answer, .output is what you want.
Max-tier ships with monthly AI quota. Each .run_sync is one slot. Loops and retries add up — write tightly.
Create a free account to get started. Paid plans unlock all tracks.
The runtime injects a configured model into your script's scope — it's the OpenRouter-backed pydantic-ai chat model, already authenticated. The smallest call:
from pydantic_ai import Agent
result = Agent(model).run_sync("Reply with a single word: hello")
print(result.output)Agent(model) wraps the model. .run_sync(prompt) blocks until done. .output is the string?
Exactly. The result object also carries token counts, tool calls, timing — but for a plain answer, .output is the field you read. Real LLM, real response, real cost (one quota slot per call).
Agent(model).run_sync(prompt).outputThe runtime hands you model ready-made. Three lines to call:
from pydantic_ai import Agent
result = Agent(model).run_sync("your prompt")
print(result.output)| In your scope | Source |
|---|---|
model | runtime injection (OpenRouter-routed, your per-user key, ready to use) |
Agent | imported from pydantic_ai |
OpenAIChatModel, OpenAIProvider | imported from pydantic_ai.models.openai if you need them (rarely — the runtime sets up model already) |
No API key handling. No provider config. The platform proxy meters per-call and uses your per-user OpenRouter key under the hood.
.run_sync vs .run.run_sync(prompt) — blocks the script until the response arrives. What you'll use 99% of the time in lessons..run(prompt) — async version, requires await. Used in async pipelines.result = Agent(model).run_sync(...) returns an object with at least:
.output — the model's text response.usage() — token counts (next time).all_messages() — the full message history (multi-turn lesson)For a plain-text answer, .output is what you want.
Max-tier ships with monthly AI quota. Each .run_sync is one slot. Loops and retries add up — write tightly.