Interface: Turn
@providerprotocol/ai / @providerprotocol/ai / Turn
Interface: Turn<TData>
Section titled “Interface: Turn<TData>”Defined in: src/types/turn.ts:88
A Turn represents the complete result of one inference call.
Includes all messages produced during tool execution loops, the final assistant response, token usage, and optional structured output data.
Example
Section titled “Example”const turn = await instance.generate('Hello');console.log(turn.response.text);console.log(`Used ${turn.usage.totalTokens} tokens in ${turn.cycles} cycles`);
// With structured outputinterface WeatherData { temperature: number; conditions: string; }const turn = await instance.generate<WeatherData>('Get weather');console.log(turn.data?.temperature);Type Parameters
Section titled “Type Parameters”TData = unknown
Type of the structured output data
Properties
Section titled “Properties”cycles
Section titled “cycles”
readonlycycles:number
Defined in: src/types/turn.ts:110
Total number of inference cycles (1 + number of tool rounds)
readonlyoptionaldata:TData
Defined in: src/types/turn.ts:116
Structured output data (if a structure schema was provided). Type is inferred from the schema when using TypeScript.
messages
Section titled “messages”
readonlymessages:Message[]
Defined in: src/types/turn.ts:93
All messages produced during this inference, in chronological order. Includes UserMessage, AssistantMessage (may include toolCalls), and ToolResultMessage.
response
Section titled “response”
readonlyresponse:AssistantMessage
Defined in: src/types/turn.ts:96
The final assistant response (last AssistantMessage in the turn)
toolExecutions
Section titled “toolExecutions”
readonlytoolExecutions:ToolExecution[]
Defined in: src/types/turn.ts:104
Tool executions that occurred during this turn.
Execution order reflects completion timing, not call order. Correlate with tool calls using toolCallId.
readonlyusage:TokenUsage
Defined in: src/types/turn.ts:107
Aggregate token usage for the entire turn