[DOCS] Incorrect property access for `total_cost_usd` in `cost-tracking.md` TypeScript examples

Resolved 💬 4 comments Opened Jan 17, 2026 by coygeek Closed Feb 28, 2026

Documentation Type

Unclear/confusing documentation

Documentation Location

URL: https://platform.claude.com/docs/en/agent-sdk/cost-tracking

Section/Topic

Section: Important Usage Rules -> 3. Result Message Contains Cumulative Usage

Current Documentation

The TypeScript code example in this section shows:

// Final result includes total usage
const result = await query({
  prompt: "Multi-step task",
  options: { /* ... */ }
});

console.log("Total usage:", result.usage);
console.log("Total cost:", result.usage.total_cost_usd); // <--- Problematic line

What's Wrong or Missing?

The property access result.usage.total_cost_usd is incorrect based on the SDK's own type definitions.

According to the Agent SDK reference - TypeScript (docs/en/agent-sdk/typescript.md), the SDKResultMessage type defines total_cost_usd as a top-level field, not a nested field within usage.

Reference from SDKResultMessage type definition:

type SDKResultMessage =
  | {
      type: 'result';
      subtype: 'success';
      // ... other fields
      total_cost_usd: number; // Top-level field
      usage: NonNullableUsage; // Sibling field
      // ...
    }

Attempting to access this via result.usage.total_cost_usd will result in a TypeScript compilation error or undefined at runtime.

Suggested Improvement

Update the TypeScript code snippet in docs/en/agent-sdk/cost-tracking.md to access the property directly from the result object.

Suggested Text:

// Final result includes total usage
const result = await query({
  prompt: "Multi-step task",
  options: { /* ... */ }
});

console.log("Total usage:", result.usage);
console.log("Total cost:", result.total_cost_usd);

Impact

High - Prevents users from using a feature

Additional Context

  • Related Documentation: This aligns with the SDKResultMessage definition found in https://platform.claude.com/docs/en/agent-sdk/typescript#sdkresultmessage.
  • Consistency: In the Python SDK section of the same page, the logic correctly accesses the attribute from the result object (e.g., result.total_cost_usd). The TypeScript example should be updated for parity and accuracy.

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗