Skip to content

Completion result ​

createCompletion(...) returns convenient display fields alongside the complete normalized provider response.

Read the result ​

ts
const result = await createCompletion(model, {
  input: 'Summarize this support ticket.',
})

console.log(result.text)
console.log(result.usage.totalTokens)
FieldContains
textVisible text extracted from the assistant content.
contentNormalized assistant content blocks.
usageNormalized token accounting.
responseThe complete normalized completion response.

Token usage ​

ts
const {
  inputTokens,
  outputTokens,
  totalTokens,
  cachedInputTokens,
  cacheCreationInputTokens,
} = result.usage

Top-level input and output counts are inclusive totals. Provider-specific pricing buckets may also be available under usage.details.

Normalized response ​

result.response exposes lower-level information when the application needs more than display text.

FieldContains
choiceThe normalized assistant content returned by the model.
usageProvider-reported token usage.
contextUsageKnown context-window occupancy for the completed request.
messageIdProvider message identifier, when available.
sourcesNormalized URL citations returned by supported providers.
providerToolCallsProvider-executed tool metadata, when available.
rawResponseThe original provider response.

Use normalized fields in product code. Keep rawResponse at integration or debugging boundaries because its shape changes by provider and may contain data that should not be logged.

Built for Anvia.