Help us shape the future of Go! Take the 2026 Go Developer Survey

metering

command
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

This sample meters model usage per tenant with an observer.

A WrapModel hook sees only the model calls of the Generate it is attached to. Here the answering model calls a tool that asks a second, cheaper model, and that call happens in a Generate of its own. An aix.Observer added to the context with tracing.WithInstrumentation sees both, so the meter bills each model at its own rate:

ctx = tracing.WithInstrumentation(ctx, aix.Observer{ModelDone: ...})

Run it:

go run .

Or with the Dev UI at http://localhost:4000:

curl -sL cli.genkit.dev | bash    # install the Genkit CLI, once
genkit start -- go run .

Or over HTTP, then ask for the tenant's running total:

curl -X POST http://localhost:8080/answerFlow \
  -H "Content-Type: application/json" \
  -d '{"data": {"tenant": "acme", "question": "Why is the sky blue?"}}'

curl -X POST http://localhost:8080/usageFlow \
  -H "Content-Type: application/json" \
  -d '{"data": "acme"}'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL