GenerateTextResult

Everything one finished generateText call produced.

The finished text is on text, but the result carries the whole run: every step the loop took, the tool calls and results within them, token usage, the reason generation stopped, and the provider's raw response.

Reach past text when you need to audit what happened: which tools ran, how many steps it took, whether it stopped because the model finished or because it hit a limit.

let result = try await generateText(
  model: AnthropicModel("claude-sonnet-5"),
  prompt: "Summarise this in one line.",
  tools: [search]
)

print(result.text)
print("\(result.steps.count) steps, \(result.usage.totalTokens) tokens")

Declaration

public struct GenerateTextResult

Defined in Sources/AI/Core/GenerateText.swift.

Properties

PropertyTypeDefault
var textString
var reasoningTextString
var toolCalls[ToolCall]
var toolResults[ToolResult]
var sources[Source]
var steps[StepResult]
var messages[Message]
var providerMetadataJSONValue?
var experimentalOutputJSONValue?nil
var finishReasonFinishReason
var usageUsage
var stepCountInt { steps.count }

See also