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

# Configuration

> Log prompt templates, model parameters, and other configuration context on your traces

This guide shows you how to attach configuration details (prompt version, model parameters, hyperparameters) to your traces using the `config` namespace.

<Tip>
  **Config vs Prompt Management:** The `config` namespace logs *which* configuration was used for a given trace. To create and deploy prompt templates, see [Managing Prompts](/v2/prompts/overview).
</Tip>

## Quick Start

Use `enrich_session()` to set the config for the entire trace, or `enrich_span()` to set it on a specific operation.

### On the Session

Set configuration context that applies to the entire user interaction:

```python theme={null}
from honeyhive import HoneyHiveTracer
import os

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
)

# ... your application logic ...

tracer.enrich_session(config={
    "model": "gpt-4o-mini",
    "prompt_version": "v2.3",
    "temperature": 0.7,
    "max_tokens": 1024,
})
```

### On a Span

Attach config to a specific function or LLM call:

```python theme={null}
from honeyhive import HoneyHiveTracer, trace
import os

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
)

@trace
def generate_summary(text: str):
    # ... your function logic ...

    tracer.enrich_span(config={
        "prompt_name": "summarizer-v3",
        "model": "gpt-4o",
        "temperature": 0.3,
        "system_prompt": "You are a concise summarizer.",
    })

    return response
```

***

## Logging a Deployed Prompt

If you use HoneyHive's [Prompt Management](/v2/prompts/overview) to deploy prompts, you can log the fetched configuration on the trace so you know exactly which version produced each response.

<Accordion title="Full example: fetch prompt and log config" icon="code">
  ```python theme={null}
  import os
  from openai import OpenAI
  from honeyhive import HoneyHive, HoneyHiveTracer, enrich_span, trace

  hh = HoneyHive(api_key=os.environ["HH_API_KEY"])
  tracer = HoneyHiveTracer.init(
      api_key=os.getenv("HH_API_KEY"),
      project=os.getenv("HH_PROJECT"),
  )
  openai_client = OpenAI()

  # Fetch the deployed prompt
  configs = hh.configurations.list()
  prompt = next(
      (c.model_dump() for c in configs
       if c.model_dump().get("name") == "my-prompt"
       and "prod" in c.model_dump().get("env", [])),
      None,
  )

  @trace
  def chat(user_message: str):
      if not prompt:
          raise ValueError("Prompt not found")

      params = prompt["parameters"]

      # Log which config produced this response
      enrich_span(config={
          "prompt_name": prompt["name"],
          "prompt_id": prompt.get("id"),
          "model": params["model"],
          "temperature": params.get("hyperparameters", {}).get("temperature"),
      })

      messages = params["template"] + [{"role": "user", "content": user_message}]
      response = openai_client.chat.completions.create(
          model=params["model"],
          messages=messages,
          **params.get("hyperparameters", {}),
      )
      return response.choices[0].message.content

  chat("Explain quantum computing simply.")
  ```
</Accordion>

***

## Concepts

### What Belongs in Config?

The `config` namespace is for any setting that controls *how* your application generates a response. This makes it easy to filter and compare traces by configuration in the dashboard.

| Category              | Example keys                                              |
| --------------------- | --------------------------------------------------------- |
| **Model selection**   | `model`, `provider`, `fallback_model`                     |
| **Prompt versioning** | `prompt_name`, `prompt_version`, `prompt_id`              |
| **Hyperparameters**   | `temperature`, `max_tokens`, `top_p`, `frequency_penalty` |
| **System behavior**   | `system_prompt`, `tool_choice`, `response_format`         |
| **Routing**           | `ab_variant`, `rollout_percentage`, `feature_flag`        |

### Config vs Metadata

Both store key-value data. Use the right namespace so you can filter effectively in the dashboard.

| Namespace  | Use for                          | Example                                  |
| ---------- | -------------------------------- | ---------------------------------------- |
| `config`   | Settings that control generation | `model`, `temperature`, `prompt_version` |
| `metadata` | Context about the request        | `request_id`, `endpoint`, `environment`  |

### Data Types

| Type    | Example                             |
| ------- | ----------------------------------- |
| String  | `"model": "gpt-4o"`                 |
| Number  | `"temperature": 0.7`                |
| Boolean | `"stream": true`                    |
| Object  | `"hyperparameters": {"top_p": 0.9}` |

***

## Learn More

<CardGroup cols={2}>
  <Card title="Managing Prompts" icon="comment-dots" href="/v2/prompts/overview">
    Create and test prompts in the Playground
  </Card>

  <Card title="Using Prompts in Code" icon="rocket" href="/v2/prompts/deploy">
    Fetch deployed prompts via the SDK
  </Card>

  <Card title="Enriching Traces" icon="sparkles" href="/v2/tracing/enrich-traces">
    Full guide to trace enrichment
  </Card>

  <Card title="Schema Reference" icon="book" href="/v2/tracing/enrichment-schema">
    All namespaces and data types
  </Card>
</CardGroup>

## SDK Reference

<CardGroup cols={2}>
  <Card title="Python SDK" icon="python" href="https://honeyhiveai.github.io/python-sdk/">
    `enrich_span()` and `enrich_session()`
  </Card>
</CardGroup>
