> ## 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.

# Using Prompts in Code

> Learn to fetch deployed prompts from HoneyHive by name or version and integrate them in your application code using the Python SDK or TypeScript API SDK.

After saving and deploying prompts in the [Playground](/v2/prompts/overview), fetch them in your application using the SDK.

## Environments

Each project has three deployment environments:

| Environment | Purpose                   |
| ----------- | ------------------------- |
| `dev`       | Development and testing   |
| `staging`   | Pre-production validation |
| `prod`      | Production deployment     |

Deploy prompts to environments in **Studio > Prompts** by selecting a saved prompt and choosing an environment.

## Fetching and Using Prompts

```python theme={null}
import os
from openai import OpenAI
from honeyhive import HoneyHive

client = HoneyHive(api_key=os.environ["HH_API_KEY"])
openai = OpenAI()

# Fetch all configurations and find the one you want
configs = client.configurations.list()

def get_prompt(name: str, env: str = "prod"):
    for c in configs:
        d = c.model_dump() if hasattr(c, "model_dump") else c
        # env is an array of deployed environments
        if d.get("name") == name and env in d.get("env", []):
            return d
    return None

# Use the prompt
prompt = get_prompt("my-prompt", "prod")
if prompt:
    params = prompt["parameters"]
    response = openai.chat.completions.create(
        model=params["model"],
        messages=params["template"],
        **params.get("hyperparameters", {})
    )
```

<Note>The Python SDK returns all configurations. Filter client-side by `name` and `env` to get specific prompts.</Note>

## Caching for Production

Cache prompts to reduce API calls:

```python theme={null}
from functools import lru_cache

@lru_cache(maxsize=100)
def get_prompt_cached(name: str, env: str = "prod"):
    configs = client.configurations.list()
    for c in configs:
        d = c.model_dump() if hasattr(c, "model_dump") else c
        if d.get("name") == name and env in d.get("env", []):
            return d
    return None

# Clear cache when prompts are updated: get_prompt_cached.cache_clear()
```

<Tip>Set a TTL on your cache to automatically refresh prompts when they're updated.</Tip>

## YAML Export

For static deployments or version control, export prompts as YAML:

```python theme={null}
import os
import yaml
from honeyhive import HoneyHive

client = HoneyHive(api_key=os.environ["HH_API_KEY"])
configs = client.configurations.list()

# Find and export a prompt
for c in configs:
    d = c.model_dump() if hasattr(c, "model_dump") else c
    if d.get("name") == "my-prompt" and "prod" in d.get("env", []):
        with open("prompts/my-prompt.yaml", "w") as f:
            yaml.dump(d, f, default_flow_style=False)
        break
```

Load in your application:

```python theme={null}
import yaml

with open("prompts/my-prompt.yaml") as f:
    config = yaml.safe_load(f)

params = config["parameters"]
template = params["template"]
model = params["model"]
```

## Related

<CardGroup cols={2}>
  <Card title="Prompt Playground" icon="comment-dots" href="/v2/prompts/overview">
    Create and test prompts before deploying.
  </Card>

  <Card title="API Reference" icon="code" href="/v2/api-reference-autogen/configurations/retrieve-a-list-of-configurations">
    Full configurations API documentation.
  </Card>
</CardGroup>
