Pydantic models used by the SDK – message hierarchy, token usage, tool calls and more.
ai_sdk.types
.
Class | Role | Typical usage |
---|---|---|
CoreSystemMessage | system | Set behaviour & identity of the assistant. |
CoreUserMessage | user | Explicit user instructions (text / images / files). |
CoreAssistantMessage | assistant | Model responses (text, reasoning, tool calls). |
CoreToolMessage | tool | Container for tool results fed back to the model. |
.to_dict()
helper that returns the OpenAI-compatible representation, so you can seamlessly drop them into the low-level LanguageModel
interface if needed.
prompt_tokens
, completion_tokens
, total_tokens
– populated on all helpers when the provider returns usage data.
GenerateTextResult
so you can inspect or persist the chain-of-thought.
on_step
callback after every model ↔ tool interaction. Fields include:
step_type
– one of initial
, continue
, tool-result
.finish_reason
, usage
, text
, tool_calls
, tool_results
, …pydantic.ConfigDict(frozen=True)
) meaning you can safely log & share
them without accidental mutation.