ls_ metadata parameters for this purpose.
These metadata parameters (all prefixed with ls_) let you pass model configuration and identification information through the standard metadata field. Once set, LangSmith can automatically calculate costs, display model information in the UI, and enable filtering and analytics across your traces.
Use ls_ metadata parameters to:
- Enable automatic cost tracking for custom or self-hosted models by identifying the provider and model name.
- Track model configuration like temperature, max tokens, and other parameters for experiment comparison.
- Filter and analyze traces by provider or configuration settings
- Improve debugging by recording exactly which model settings were used for each run.
Basic usage example
The most common use case is enabling cost tracking for custom model wrappers. To do this, you need to provide two key pieces of information: the provider name (ls_provider) and the model name (ls_model_name). These work together to match against LangSmith’s pricing database.
ls_provider and ls_model_name pair needed for cost tracking.
All parameters
User-configurable parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
ls_provider | string | Yes* | LLM provider name for cost tracking |
ls_model_name | string | Yes* | Model identifier for cost tracking |
ls_temperature | number | No | Temperature parameter used |
ls_max_tokens | number | No | Maximum tokens parameter used |
ls_stop | string[] | No | Stop sequences used |
ls_invocation_params | object | No | Additional invocation parameters |
ls_provider and ls_model_name must be provided together for cost tracking
System-generated parameters
| Parameter | Type | Description |
|---|---|---|
ls_run_depth | integer | Depth in trace tree (0=root, 1=child, etc.) - automatically calculated |
ls_method | string | Tracing method used (e.g., “traceable”) - set by SDK |
Experiment parameters
| Parameter | Type | Description |
|---|---|---|
ls_example_* | any | Example metadata prefixed with ls_example_ - added during experiments |
ls_experiment_id | string (UUID) | Unique experiment identifier - added during experiments |
Parameter details
ls_provider
- Type:
string - Required: Yes (with
ls_model_name)
ls_model_name, enables automatic cost calculation by matching against LangSmith’s model pricing database.
Common values:
"openai""anthropic""azure""bedrock""google_vertexai""google_genai""fireworks""mistral""groq"- Or, any custom string
- Requires
ls_model_namefor cost tracking to work. - Works with token usage data to calculate costs.
ls_model_name
- Type:
string - Required: Yes (with
ls_provider)
ls_provider, matches against pricing database for automatic cost calculation.
Common values:
- OpenAI:
"gpt-4o","gpt-4o-mini","gpt-3.5-turbo" - Anthropic:
"claude-3-5-sonnet-20241022","claude-3-opus-20240229" - Custom: Any model identifier
- Requires
ls_providerfor cost tracking to work. - Works with token usage data to calculate costs.
ls_temperature
- Type:
number(nullable) - Required: No
- Independent; just for tracking.
- Useful alongside other config parameters for experiment comparison.
ls_max_tokens
- Type:
number(nullable) - Required: No
- Independent; just for tracking.
- Useful for cost analysis when combined with actual token usage.
ls_stop
- Type:
string[](nullable) - Required: No
- Independent; just for tracking.
ls_invocation_params
- Type:
object(any key-value pairs) - Required: No
ls_ parameters. Can include provider-specific settings.
Common parameters:
top_p, frequency_penalty, presence_penalty, top_k, seed, or any custom parameters
When to use:
When you need to track additional configuration beyond the standard parameters.
Example:
- Independent; stores arbitrary configuration.
ls_run_depth
- Type:
integer - Set by: LangSmith backend (automatic)
- Cannot be overridden
0= Root run (top-level)1= Direct child2= Grandchild- etc.
- Determined by trace parent-child structure.
- Cannot be set manually.
ls_method
- Type:
string - Set by: SDK (automatic)
"traceable" for @traceable decorator).
When it’s used:
Automatically set by the tracing SDK. Used for debugging and analytics.
Relationships:
- Set by SDK based on how trace was created.
- Cannot be set manually.
ls_example_*
- Type: Any (depends on example metadata)
- Pattern:
ls_example_{original_key} - Set by: LangSmith experiments system (automatic)
ls_example_ and added to the trace.
Special parameter:
ls_example_dataset_split: Dataset split (e.g., “train”, “test”, “validation”)
{"category": "technical", "difficulty": "hard"}, trace gets:
- Automatically derived from example metadata.
- Cannot be set manually on traces.
ls_experiment_id
- Type:
string(UUID) - Set by: LangSmith experiments system (automatic)
- Links runs to specific experiments.
- Cannot be set manually.
Parameter relationships
Cost tracking dependencies
For LangSmith to automatically calculate costs, several parameters must work together. Here’s what’s required: Primary requirement:ls_provider + ls_model_name
- Both should be present for automatic cost calculation.
- If
ls_model_nameis missing, system will fall back to checkingls_invocation_paramsfor model name. ls_providermust match a provider in the pricing database (or use custom pricing).
- Run must have
run_type="llm"(or arbitrary cost tracking must be enabled). - Token usage data must be present in the trace (prompt_tokens, completion_tokens).
- Model must exist in pricing database or have custom pricing configured.
ls_model_name is not in metadata, the system checks ls_invocation_params for model identifiers like "model" before giving up on cost tracking.
Configuration tracking group
These parameters help you track model settings but don’t affect LangSmith’s core functionality: Optional, work independently:ls_temperature, ls_max_tokens, ls_stop
- These are for tracking/display.
- Do not affect LangSmith behavior or cost calculation.
- Useful for experiment comparison and debugging.
Invocation params special case
Thels_invocation_params parameter has a dual role as both a tracking field and a fallback mechanism:
ls_invocation_params; partially independent with fallback role:
- Primarily stores arbitrary configuration for tracking.
- Can serve as fallback for cost tracking if
ls_model_nameis missing. - Does not directly affect cost calculation when
ls_model_nameis present.
System parameters
These parameters are automatically generated by LangSmith and cannot be manually set: Cannot be user-set:ls_run_depth, ls_method, ls_example_*, ls_experiment_id
- Automatically set by system.
- Used for filtering, analytics, and system tracking.
Filter traces by metadata parameters
Once you’ve addedls_ metadata parameters to your traces, you can use them to filter and search traces programmatically via the API or interactively in the LangSmith UI. This lets you narrow down traces by model, provider, configuration settings, or trace depth.
Use the API
Use theClient class with the list_runs() method (Python) or listRuns() method (TypeScript) to query traces based on metadata values. The filter syntax supports equality checks, comparisons, and logical operators.
- Filter by provider or model to analyze usage patterns or costs for specific models
- Filter by run depth to get only root traces (depth 0) or child runs at specific nesting levels
- Filter by configuration to compare experiments with different temperature, max tokens, or other settings
Use the UI
In the LangSmith UI, use the filter/search bar with the filter syntax:Related resources
- Cost tracking guide: Learn how to track and analyze LLM costs in LangSmith.
- Log LLM traces: Format requirements for logging LLM calls with proper token tracking.
- Trace query syntax: Complete reference for filtering and searching traces.
- Evaluation quickstart: Run experiments on datasets to compare model configurations.
- Add metadata and tags: General guide to adding metadata to traces.
- Filter traces in application: Programmatically filter traces in your code.