Skip to content

Custom Headers

Both fetch methods accept an optional headers argument — a dict of header name → value strings — that's merged into the outgoing HTTP request.

python
prompt = pm.get_active_prompt_version(
    "welcome_email",
    headers={"X-Request-Id": "abc-123"},
)

Common uses

Distributed tracing

Propagate traceparent, X-Request-Id, or your team's tracing header into the Prompt Manager request log.

Tenant tagging

Attach a X-Tenant-Id so log analysis can correlate prompt fetches with specific customers.

Custom auth proxies

If your on-prem instance sits behind a corporate gateway, pass through the gateway's expected headers (X-Forwarded-User, etc.).

Debug flags

Some internal debug headers your backend recognizes (e.g. X-Debug-Verbose: 1).

Example — distributed tracing

Forward the active traceparent from your incoming request:

python
from fastapi import FastAPI, Request
from app.deps import pm

app = FastAPI()

@app.get("/welcome")
def welcome(request: Request):
    traceparent = request.headers.get("traceparent")
    headers = {"traceparent": traceparent} if traceparent else None

    prompt = pm.get_active_prompt_version("welcome_email", headers=headers)
    return {"text": prompt.render({"name": "Ada"})}

Example — per-call request id

Generate a unique ID per fetch and tag your logs with it:

python
import uuid
import logging

logger = logging.getLogger(__name__)

def fetch_with_id(prompt_name):
    rid = str(uuid.uuid4())
    logger.info(f"Fetching prompt {prompt_name!r}, request_id={rid}")
    return pm.get_active_prompt_version(prompt_name, headers={"X-Request-Id": rid})

Copyright © 2026 elsai foundry.