Skip to content

Commit 987774e

Browse files
authored
fix(ai): Mention that cached and reasoning tokens are subsets of input and output tokens (#15195)
Clarify how to manually instrument usage tokens in AI agent monitoring.
1 parent af654b2 commit 987774e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

develop-docs/sdk/telemetry/traces/modules/ai-agents.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ Additional attributes on the span:
6363
| Attribute | Type | Requirement Level | Description | Example |
6464
| :------------------------------------- | :--- | :---------------- | :------------------------------------------------------------------------ | :------ |
6565
| `gen_ai.usage.input_tokens` | int | optional | The number of tokens used in the AI input (prompt). | `10` |
66-
| `gen_ai.usage.input_tokens.cached` | int | optional | The number of cached tokens used in the AI input (prompt) | `50` |
66+
| `gen_ai.usage.input_tokens.cached` | int | optional | The number of cached tokens used in the AI input (prompt) **[2]** | `50` |
6767
| `gen_ai.usage.output_tokens` | int | optional | The number of tokens used in the AI response. | `100` |
68-
| `gen_ai.usage.output_tokens.reasoning` | int | optional | The number of tokens used for reasoning. | `30` |
68+
| `gen_ai.usage.output_tokens.reasoning` | int | optional | The number of tokens used for reasoning. **[3]** | `30` |
6969
| `gen_ai.usage.total_tokens` | int | optional | The total number of tokens used to process the prompt. (input and output) | `190` |
7070

7171
- **[0]:** Span attributes only allow primitive data types (like `int`, `float`, `boolean`, `string`). This means you need to use a stringified version of a list of dictionaries. Do NOT set the object/array `[{"foo": "bar"}]` but rather the string `'[{"foo": "bar"}]'` (must be parsable JSON).
7272
- **[1]:** Each message item uses the format `{role:"", content:""}`. The `role` must be `"user"`, `"assistant"`, `"tool"`, or `"system"`. For messages of the role `tool`, the `content` can be a string or an arbitrary object with information about the tool call. For other messages the `content` can be either a string or a list of dictionaries in the format `{type: "text", text:"..."}`.
73+
- **[2]:** Cached tokens are a subset of input tokens; `gen_ai.usage.input_tokens` includes `gen_ai.usage.input_tokens.cached`.
74+
- **[3]:** Reasoning tokens are a subset of output tokens; `gen_ai.usage.output_tokens` includes `gen_ai.usage.output_tokens.reasoning`.
7375

7476
## AI Client Span
7577

@@ -106,13 +108,15 @@ Additional attributes on the span:
106108
| Attribute | Type | Requirement Level | Description | Example |
107109
| :------------------------------------- | :--- | :---------------- | :------------------------------------------------------------------------ | :------ |
108110
| `gen_ai.usage.input_tokens` | int | optional | The number of tokens used in the AI input (prompt). | `10` |
109-
| `gen_ai.usage.input_tokens.cached` | int | optional | The number of cached tokens used in the AI input (prompt) | `50` |
111+
| `gen_ai.usage.input_tokens.cached` | int | optional | The number of cached tokens used in the AI input (prompt) **[2]** | `50` |
110112
| `gen_ai.usage.output_tokens` | int | optional | The number of tokens used in the AI response. | `100` |
111-
| `gen_ai.usage.output_tokens.reasoning` | int | optional | The number of tokens used for reasoning. | `30` |
113+
| `gen_ai.usage.output_tokens.reasoning` | int | optional | The number of tokens used for reasoning. **[3]** | `30` |
112114
| `gen_ai.usage.total_tokens` | int | optional | The total number of tokens used to process the prompt. (input and output) | `190` |
113115

114116
- **[0]:** Span attributes only allow primitive data types (like `int`, `float`, `boolean`, `string`). This means you need to use a stringified version of a list of dictionaries. Do NOT set the object/array `[{"foo": "bar"}]` but rather the string `'[{"foo": "bar"}]'` (must be parsable JSON).
115117
- **[1]:** Each message item uses the format `{role:"", content:""}`. The `role` must be `"user"`, `"assistant"`, `"tool"`, or `"system"`. For messages of the role `tool`, the `content` can be a string or an arbitrary object with information about the tool call. For other messages the `content` can be either a string or a list of dictionaries in the format `{type: "text", text:"..."}`.
118+
- **[2]:** Cached tokens are a subset of input tokens; `gen_ai.usage.input_tokens` includes `gen_ai.usage.input_tokens.cached`.
119+
- **[3]:** Reasoning tokens are a subset of output tokens; `gen_ai.usage.output_tokens` includes `gen_ai.usage.output_tokens.reasoning`.
116120

117121
## Execute Tool Span
118122

0 commit comments

Comments
 (0)