# Run evaluation
res = evaluate(
    experiment_name="SQL question answering",
    dataset=dataset,
    task=evaluation_task,
    scoring_metrics=[valid_sql_query],
    nb_samples=20,
)
```

The evaluation results are now uploaded to the Opik platform and can be viewed in the UI.

<Frame>
  <img src="https://files.buildwithfern.com/https://opik.docs.buildwithfern.com/docs/opik/2026-01-30T17:33:07.444Z/img/cookbook/langchain_cookbook.png" />
</Frame>

## Cost Tracking

The `OpikTracer` automatically tracks token usage and cost for all supported LLM models used within LangChain applications.

Cost information is automatically captured and displayed in the Opik UI, including:

* Token usage details
* Cost per request based on model pricing
* Total trace cost

<Tip>
  View the complete list of supported models and providers on the [Supported Models](/tracing/supported_models) page.
</Tip>

For streaming with cost tracking, ensure `stream_usage=True` is set:

```python
from langchain_openai import ChatOpenAI
from opik.integrations.langchain import OpikTracer

llm = ChatOpenAI(
    model="gpt-4o",
    streaming=True,
    stream_usage=True,  # Required for cost tracking with streaming
)

opik_tracer = OpikTracer()

for chunk in llm.stream("Hello", config={"callbacks": [opik_tracer]}):
    print(chunk.content, end="")
```

<Tip>
  View the complete list of supported models and providers on the [Supported Models](/tracing/supported_models) page.
</Tip>

## Settings tags and metadata

You can customize the `OpikTracer` callback to include additional metadata, logging options, and conversation threading:

```python
from opik.integrations.langchain import OpikTracer

opik_tracer = OpikTracer(
    tags=["langchain", "production"],
    metadata={"use-case": "customer-support", "version": "1.0"},
    thread_id="conversation-123",  # For conversational applications
    project_name="my-langchain-project"
)
```

## Accessing logged traces

You can use the [`created_traces`](https://www.comet.com/docs/opik/python-sdk-reference/integrations/langchain/OpikTracer.html) method to access the traces collected by the `OpikTracer` callback:

```python
from opik.integrations.langchain import OpikTracer

opik_tracer = OpikTracer()