Skip to content

Conversation

@avivhalfon
Copy link
Contributor

@avivhalfon avivhalfon commented Sep 4, 2025

Important

Adds selected_token_types parameter to filter costs by token types in property_costs.mdx.

  • Request Parameters:
    • Adds selected_token_types parameter to filter costs by token types in property_costs.mdx.
    • Supported token types include input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens, and others.
    • total_tokens cannot be used as a filter.
    • When omitted, all token types are included.

This description was created by Ellipsis for 0db0403. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features
    • Added optional selected_token_types parameter to “Get costs by property,” enabling cost filtering by token types. Supports prompt/input, completion/output, cache_read_input_tokens, cache_creation_input_tokens, and other available types. total_tokens is not supported. When omitted, returns costs for all token types. No response changes.
  • Documentation
    • Updated API reference with parameter details, normalization notes (input→prompt, output→completion), and example queries, placed after the env parameter.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

Walkthrough

Adds an optional selected_token_types query parameter to the “Get costs by property” API documentation, enabling cost filtering by specified token types. Supports several token-type values with normalization rules; total_tokens is excluded. Examples added. No response schema changes.

Changes

Cohort / File(s) Summary
API Docs: Costs filter parameter
api-reference/costs/property_costs.mdx
Documented new optional selected_token_types (string) query parameter to filter costs by token types; includes supported values, normalization notes, exclusions (cannot filter by total_tokens), examples, and placement after env; response fields unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant API as Costs API
  participant S as Cost Aggregator

  Note over C,API: Request: GET /costs/by-property
  rect rgb(235, 245, 255)
    C->>API: selected_token_types=? (optional)
    alt With selected_token_types
      API->>S: Fetch costs filtered by specified token types
      S-->>API: Aggregated costs (filtered)
    else Without selected_token_types
      API->>S: Fetch costs for all token types
      S-->>API: Aggregated costs (all types)
    end
  end
  API-->>C: 200 OK with cost breakdown (unchanged schema)

  Note over API: total_tokens not allowed as a filter
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my ears at tokens’ trails,
Sorting seeds of prompts and tales—
Input sprigs, completion blooms,
Cache-kissed leaves in ledger rooms.
Hop, hop! I filter, light and neat;
All costs aligned beneath my feet.
Carrot-balanced, tokens complete.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ah/add-filter-docs

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@avivhalfon avivhalfon changed the title chore(docs): add new docs chore(docs): add new filter costs by token type docs Sep 4, 2025
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed everything up to 0db0403 in 52 seconds. Click for details.
  • Reviewed 31 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. api-reference/costs/property_costs.mdx:27
  • Draft comment:
    Ensure the inline JSX 'NEW' badge style renders correctly in MDX.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. api-reference/costs/property_costs.mdx:29
  • Draft comment:
    Docs are clear; consider adding explicit details on token normalization for non-standard types.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_IySzW12y27F7cx1X

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
api-reference/costs/property_costs.mdx (5)

26-44: Clarify filter semantics and aggregation scope.

State explicitly that the filter sums the selected token types (union) and that all returned costs (including total_cost) reflect only those selected types. This prevents readers from assuming per-type breakdowns.

 <ParamField query="selected_token_types" type="string">
-  <span style={{backgroundColor: '#10b981', color: 'white', padding: '2px 6px', borderRadius: '4px', fontSize: '12px', fontWeight: 'bold'}}>NEW</span> Filter costs by specific token types. Separate multiple types with commas.
+  <span style={{backgroundColor: '#10b981', color: 'white', padding: '2px 6px', borderRadius: '4px', fontSize: '12px', fontWeight: 'bold'}}>NEW</span> Filter costs by specific token types. Separate multiple types with commas (CSV).
+  
+  Costs are aggregated across the selected types (union). The response schema is unchanged; all cost figures (including "total_cost") reflect only the selected token types.

29-35: Define normalization details (case/whitespace) to avoid client-side ambiguity.

Readers need to know if values are case-insensitive and whether spaces around commas are accepted.

   **Supported token types:**
   - `input_tokens` or `prompt_tokens` (automatically normalized to `prompt_tokens`)
   - `output_tokens` or `completion_tokens` (automatically normalized to `completion_tokens`)
   - `cache_read_input_tokens`
   - `cache_creation_input_tokens`
   - Other token types as they appear in your data
+  
+  Matching is case-insensitive and surrounding whitespace is ignored (e.g., `prompt_tokens, completion_tokens` is valid).

36-44: Document behavior for unsupported values, including total_tokens.

Specify whether the API rejects the request (preferred: 400 with details) or ignores invalid values. This affects client error handling.

   **Note:** `total_tokens` cannot be used as a filter.
+  
+  If an unsupported value (including `total_tokens`) is provided, the API returns a 400 Bad Request with an error message listing allowed values. 
+  (Confirm actual behavior and adjust this note accordingly.)

27-27: Prefer a reusable Badge component over inline styles.

If the docs site provides a Badge/Label component, use it for consistency and theming.

-  <span style={{backgroundColor: '#10b981', color: 'white', padding: '2px 6px', borderRadius: '4px', fontSize: '12px', fontWeight: 'bold'}}>NEW</span> Filter costs by specific token types. Separate multiple types with commas.
+  <Badge color="green">NEW</Badge> Filter costs by specific token types. Separate multiple types with commas.

If no Badge component exists, ignore this suggestion.


38-44: Add a concrete curl example showing CSV usage and URL encoding.

A real request helps users copy/paste and reduces mistakes.

   **Examples:**
   - `selected_token_types=input_tokens,output_tokens`
   - `selected_token_types=prompt_tokens,cache_read_input_tokens`
   - `selected_token_types=completion_tokens`
   
   When this parameter is omitted, costs for all token types are included.
+  
+  Example request:
+  ```bash
+  curl -G 'https://api.traceloop.com/api/v2/costs/by-association-property' \
+    --data-urlencode 'property_name=session_id' \
+    --data-urlencode 'start_time=2025-04-15T00:00:00Z' \
+    --data-urlencode 'end_time=2025-04-28T23:00:00Z' \
+    --data-urlencode 'selected_token_types=prompt_tokens,completion_tokens'
+  ```
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bb38475 and 0db0403.

📒 Files selected for processing (1)
  • api-reference/costs/property_costs.mdx (1 hunks)

@avivhalfon avivhalfon merged commit fae41a2 into main Sep 4, 2025
4 checks passed
@avivhalfon avivhalfon deleted the ah/add-filter-docs branch September 4, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants