Skip to content

Interface: Turn

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / Turn

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.

const turn = await instance.generate('Hello');
console.log(turn.response.text);
console.log(`Used ${turn.usage.totalTokens} tokens in ${turn.cycles} cycles`);
// With structured output
interface WeatherData { temperature: number; conditions: string; }
const turn = await instance.generate<WeatherData>('Get weather');
console.log(turn.data?.temperature);

TData = unknown

Type of the structured output data

readonly cycles: number

Defined in: src/types/turn.ts:110

Total number of inference cycles (1 + number of tool rounds)


readonly optional data: 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.


readonly messages: 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.


readonly response: AssistantMessage

Defined in: src/types/turn.ts:96

The final assistant response (last AssistantMessage in the turn)


readonly toolExecutions: 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.


readonly usage: TokenUsage

Defined in: src/types/turn.ts:107

Aggregate token usage for the entire turn