LangChain Support
Back to LangSmith Observability

How do I get monthly trace costs by workspace using the API?

LangSmith Observability·2 min read·Jan 30, 2026··

Context

You want to programmatically retrieve monthly trace costs broken down by workspace for cost allocation and reporting purposes. This allows you to track LangSmith usage costs for different teams or services and include them in automated cost reporting workflows.

Answer

Currently, you can retrieve trace usage data by workspace using the granular usage API, but you'll need to calculate the actual costs yourself since the API doesn't directly provide dollar amounts.

Here's how to get the usage data:

  1. Use the granular usage API endpoint:

    curl -X GET \
      "https://api.smith.langchain.com/api/v1/orgs/current/billing/usage \
      -H "X-Api-Key: <API KEY HERE>" \
      -H "Content-Type: application/json" | jq .
  2. Combine with the workspaces endpoint to get workspace-specific information and map usage to workspaces.

  3. Calculate costs by applying your pricing model to the trace counts returned by the API.

Adding external IDs to workspaces:

If you need to tag workspaces with external service IDs for easier mapping:

  • For new workspaces: Configure the tenant_handle field to include your external ID when creating the workspace

  • For existing workspaces: You can update the display_name to include the external ID, though this may not be ideal since it affects the visible workspace name

Note: There is an ongoing feature request to add direct cost breakdown per workspace and improved workspace metadata/tagging capabilities to the API.

Sources: LangSmith API documentation at https://api.smith.langchain.com/redoc