Before diving into this content, it might be helpful to read the following:
Some of the features mentioned in this guide are not currently available in Enterprise plan due to its custom nature of billing. If you are on Enterprise plan and have questions about cost optimization, please reach out to your sales rep or support@langchain.dev.
Problem Setup
In this tutorial, we take an existing organization that has three workspaces, one for each deployment stage (Dev, Staging, and Prod):
Understand your current usage
The first step of any optimization process is to understand current usage. LangSmith gives two ways to do this: Usage Graph and Invoices.Usage Graph
The usage graph lets us examine how much of each usage based pricing metric we have consumed lately. It does not directly show spend (which we will see later on our draft invoice). We can navigate to the Usage Graph underSettings
-> Usage and Billing
-> Usage Graph
.

- LangSmith Traces (Base Charge)
- LangSmith Traces (Extended Data Retention Upgrades).
Invoices
We understand what usage looks like in terms of traces, but we now need to translate that into spend. To do so, we head to theInvoices
tab. The first invoice that will appear on screen is a draft of your current month’s invoice, which shows your running spend thus far this month.

LangSmith’s Usage Graph and Invoice use the term
tenant_id
to refer to a workspace ID. They are interchangeable.- You use extended data retention tracing, meaning that, by default, your traces are retained for 400 days
- You use base data retention tracing, and use a feature that automatically extends the data retention of a trace (see our Auto-Upgrade conceptual docs)
Optimization 1: manage data retention
LangSmith charges differently based on a trace’s data retention (see our data retention conceptual docs), where short-lived traces are an order of magnitude less expensive than ones that last for a long time. In this optimization, we will show how to get optimal settings for data retention without sacrificing historical observability, and show the effect it has on our bill.Change org level retention defaults for new projects
Navigate to the Usage configuration tab, and look at our organization level retention settings. Modifying this setting affects all new projects that are created going forward in all workspaces in our org.For backwards compatibility, older organizations may have this defaulted to Extended. Organizations created after June 3rd, 2024 have this defaulted to Base.

Change project level retention defaults
Data retention settings are adjustable per project on the tracing project page. Navigate to Projects > Your project name > Select Retention and modify the default retention of the project to Base. This will only affect retention (and pricing) for traces going forward.
Apply extended data retention to a percentage of traces
You may not want all traces to expire after 14 days. You can automatically extend the retention of traces that match some criteria by creating an automation rule. You might want to apply extended data retention to specific types of traces, such as:- 10% of all traces: For general analysis or analyzing trends long-term
- Errored traces: To thoroughly investigate and debug issues
- Traces with specific metadata: For long-term examination of particular features or user flows
- Navigate to Projects > Your project name > Select + New > Select New Automation
- Name your rule and optionally apply filters or a sample rate. For more information on configuring filters, see filtering techniques
For example, this is what the configuration looks like to keep 10% of all traces for extended data retention:

See results after 7 days
While the total amount of traces per day stayed the same, the extended data retention traces was cut heavily. In the invoice, we can see that we’ve only spent about $900 in the last 7 days, as opposed to $2,000 in the previous 4. That’s a cost reduction of nearly 75% per day!
Optimization 2: limit usage
In the previous section, we managed data retention settings to optimize existing spend. In this section, we will use usage limits to prevent future overspend. LangSmith has two usage limits: total traces and extended retention traces. These correspond to the two metrics we’ve been tracking on our usage graph. We can use these in tandem to have granular control over spend. To set limits, we navigate back toSettings
-> Usage and Billing
-> Usage configuration
. There is a table at the bottom of the page that lets you set usage limits per workspace. For each workspace, the two limits appear, along with a cost estimate:

Setting a good total traces limit
Picking the right “total traces” limit depends on the expected load of traces that you will send to LangSmith. You should clearly think about your assumptions before setting a limit. For example:- Current Load: Our gen AI application is called between 1.2-1.5 times per second, and each API request has a trace associated with it, meaning we log around 100,000-130,000 traces per day
- Expected Growth in Load: We expect to double in size in the near future.

When set without the extended data retention traces limit, the maximum cost estimator assumes that all traces are using extended data retention.
Cutting maximum spend with an extended data retention limit
If we are not a big enterprise, we may shudder at the ~$40k per month bill. We saw from Optimization 1 that the easiest way to cut cost was through managing data retention. The same can be said for limits. If we only want to keep ~10% of traces to be around more than 14 days, we can set a limit on the maximum high retention traces we can keep. That would be.10 * 7,800,000 = 780,000
.

The extended data retention limit can cause features other than traces to stop working once reached. If you plan to use this feature, please read more about its functionality here.
Set dev/staging limits and view total spent limit across workspaces
Following the same logic for our dev and staging environments, we set limits at 10% of the production limit on usage for each workspace. While this works with our usage pattern, setting good dev and staging limits may vary depending on your use case with LangSmith. For example, if you run evals as part of CI/CD in dev or staging, you may want to be more liberal with your usage limits to avoid test failures. Now that our limits are set, we can see that LangSmith shows a maximum spend estimate across all workspaces:
Summary
In this tutorial, we learned how to:- Cut down our existing costs with data retention policies
- Prevent future overspend with usage limits