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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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