> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tracepress.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Choose a model

TracePress has no default model. Every LM operator needs one, and you pick it in one of
two ways:

```python theme={null}
tp.configure(lm="openrouter:openai/gpt-6-luna")  # for everything
notes = steps.lm_map("step_text -> summary", lm="...")  # for one operator
```

A run without a model fails before it makes any calls.

`openrouter:openai/gpt-6-luna` is the suggested model. It's cheap (about $0.10 per million input
tokens and $0.50 per million output tokens) and works well for trace analysis.

## Model strings

Use a gateway prefix (`openrouter:`, `portkey:`, `typesafe:`), or name a provider directly.

| String | Goes to | Needs |
| - | - | - |
| `openrouter:openai/gpt-6-luna` | OpenRouter | `OPENROUTER_API_KEY` |
| `portkey:openai-prod/gpt-5` | Portkey's gateway, model `@openai-prod/gpt-5` from your Model Catalog | `PORTKEY_API_KEY` |
| `typesafe:jev-latest` | TypeSafe's Jev, for decision-only stages (see [Jev](#jev)) | `TYPESAFE_API_KEY` |
| `anthropic/claude-opus-5` | Anthropic directly | `ANTHROPIC_API_KEY` |
| `openai/gpt-5` | OpenAI directly | `OPENAI_API_KEY` |

* **Portkey:** the part before the `/` is your Model Catalog provider slug. Writing
  `portkey:@openai-prod/gpt-5` means the same thing. Set `PORTKEY_BASE_URL` to use a
  self-hosted gateway.
* **Colons in model names:** a colon after a `/` is part of the model name, so strings like
  `ollama_chat/llama3:8b` work as written.
* **Options:** wrap a model string in `tp.LM` to set options such as temperature or an endpoint,
  e.g. `tp.LM("openrouter:openai/gpt-6-luna", temperature=0.0)`. It takes the same options as
  [`dspy.LM`](https://dspy.ai/learn/programming/language_models/).

Keys are read from the environment, or from a `.env` file in the working directory.

## Jev

Jev, TypeSafe's System One model, can be a cheaper option for stages that only make decisions,
such as flagging steps or picking a category. It doesn't write text: it answers yes/no
(`Noul`) or picks among fixed options (`Choice`), with probabilities. Each output needs a `desc`,
which Jev reads as the question:

```python theme={null}
from typing import Annotated, Literal

import dspy
from dspy.experimental import Choice, Noul


class Triage(dspy.Signature):
    step_text: str = dspy.InputField()
    failed: Noul = dspy.OutputField(desc="Did this step fail?")
    kind: Annotated[Literal["tool", "reasoning", "planning"], Choice] = dspy.OutputField(
        desc="What kind of mistake it is, if any")


judged = steps.lm_map(Triage, lm="typesafe:jev-latest")

for row in judged.collect()[:3]:
    print(row.step, row.failed.value, row.failed.probability, row.kind)
```

`failed` comes back with Jev's probability, and `kind` as the chosen option. For example (values
made up to show the shape):

```text theme={null}
1 False 0.03 planning
2 False 0.11 tool
3 True 0.87 tool
```

## Local models

Any locally hosted model works, so your traces never leave your machine.

* **Ollama:** use `ollama_chat/<model>`, e.g. `tp.configure(lm="ollama_chat/llama3.1")`. It talks to
  Ollama on `localhost:11434` by default.
* **vLLM, llama.cpp, LM Studio, or any other OpenAI-compatible server:** point a `tp.LM` at it:

  ```python theme={null}
  tp.configure(lm=tp.LM("openai/my-model", api_base="http://localhost:8000/v1", api_key="local"))
  ```

Local models have no price, so their calls show up as `unpriced_calls` in `tp.last_run()`. Add a
price with `tp.configure(prices=...)` if you want a cost estimate.

## Cost and caching

Every call is cached on disk, so rerunning a pipeline only pays for prompts that
changed. After a run, `tp.last_run()` shows what it did:

```python theme={null}
>>> tp.last_run()
RunStats(calls=186, errors=0, fallbacks=0, timeouts=0, prompt_tokens=132982, completion_tokens=39700,
         cached_prompt_tokens=5120, cached_completion_tokens=1490, cost=$0.033148, seconds=37.3)
```

Calls answered from the disk cache send no request and cost nothing, so they aren't in
`prompt_tokens` or `completion_tokens`. What those calls used when they were first made is
counted in `cached_prompt_tokens` and `cached_completion_tokens`: the tokens the cache saved you.

`by_model` and `by_op` break the totals down by model and by operator. `latency()` gives
per-call percentiles. `status` is `running`, `completed`, `failed` or `cancelled`, and `error`
holds what ended a run that didn't complete. During a live run, `tp.last_run()` shows the totals so far.

Cost is estimated from token counts. Prices come from a bundled price table, plus
built-in entries for the suggested model and Jev. When a provider reports a call's cost (OpenRouter
does for models with no listed price), that's used instead. Add your own prices, in USD per
million input and output tokens, keyed by the model name:

```python theme={null}
tp.configure(prices={"openai/my-model": (0.50, 2.00)})
```

These are added to the prices already configured; an entry for a model that already has a
price replaces it.

Calls to models with no known price are counted as `unpriced_calls` instead of being guessed.

## Next steps

* [Optimization](https://docs.tracepress.ai/cookbooks/optimize.md): improve a step against your labels.
* [Live pipelines](https://docs.tracepress.ai/cookbooks/live.md): run a model on traces as they arrive.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.