TypeSafe.Usage (TypeSafe AI v0.1.0-alpha.1)

Copy Markdown View Source

Token counts for one call, when the API reports them.

The official SDKs treat input_tokens/output_tokens as optional: the wire usage object may leave either out, or send it as null. This module mirrors that instead of raising, so a caller who doesn't track usage never has to think about it, and a caller who does gets nil instead of a crash.

Summary

Functions

Decodes the wire usage object. A missing map, or a token count that isn't a non-negative integer, decodes to nil for that field rather than failing.

Types

t()

@type t() :: %TypeSafe.Usage{
  input_tokens: non_neg_integer() | nil,
  output_tokens: non_neg_integer() | nil
}

Functions

decode(usage)

@spec decode(map() | nil) :: t()

Decodes the wire usage object. A missing map, or a token count that isn't a non-negative integer, decodes to nil for that field rather than failing.