spans when your application needs to control that itself. For example, you may want to attribute one specific occurrence of a repeated number, or run a controlled experiment over fixed ranges.
With spans, TokenPath attributes exactly the ranges you send and nothing else. The response has one entry per range, in the order you sent them.
[13, 26] covers $5.87 billion and [42, 45] covers 11%. The response keeps your order:
15% values to the two different clauses they came from.
Rules
- Each span is a half-open
[start, end]range intoanswer, with0 <= start < end <= len(answer). - Offsets use the request’s
offset_encoding, and so does thelen(answer)bound. See Offsets and encoding. - Send at least one span.
"spans": []and"spans": nullfail with422 validation_error. To let TokenPath choose, leave the field out. - A span whose phrase has no support comes back with
"source": null.
Keep spans short
Attribution works best on fact-sized phrases, such as a number, a name, a date, an ID, or a short entity. Aim for 1 to 8 words. Numbers, dates, and names are usually best at 1 to 4. Good spans:$5.87 billion11%March 2, 2026Jordan Leeremaining performance obligations9,420 customers
The
[[...]] marks only show the selected ranges. Strip them before you send the answer.
Selecting spans during generation
One way to get ranges is to ask the model to mark them as it writes:Offset encoding
Explicit spans are read in the request’soffset_encoding, which defaults to utf-16. The helper above produces Python code-point offsets, so send "offset_encoding": "utf-32" with them. Offsets and encoding covers every language.