Skip to main content
This guide shows how to add Muxx to an existing application with minimal changes.

Before You Start

You’ll need:
  • A Muxx account
  • Your Muxx API key
  • 5 minutes

Gateway Migration (Fastest)

The gateway approach requires just a base URL change.

Before

from openai import OpenAI

client = OpenAI()  # Uses api.openai.com

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

After

from openai import OpenAI

client = OpenAI(
    base_url="https://gateway.muxx.dev/v1",
    default_headers={
        "X-Muxx-Api-Key": "muxx_sk_live_xxxxxxxxxxxx"
    }
)

# Everything else stays the same!
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)
Changes required: 2 lines

SDK Migration

For deeper tracing, use the SDK wrapper.

Before

from openai import OpenAI

client = OpenAI()

def summarize(text: str) -> str:
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": f"Summarize: {text}"}]
    )
    return response.choices[0].message.content

After

from muxx import Muxx
from openai import OpenAI

muxx = Muxx()
client = muxx.wrap(OpenAI())  # Wrap the client

def summarize(text: str) -> str:
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": f"Summarize: {text}"}]
    )
    return response.choices[0].message.content
Changes required: 3 lines (import, init, wrap)

Adding Traces

Once migrated, optionally add traces for better organization:
from muxx import Muxx, trace
from openai import OpenAI

muxx = Muxx()
client = muxx.wrap(OpenAI())

@trace("document-processing")
def process_document(doc: str) -> dict:
    summary = summarize(doc)
    entities = extract_entities(doc)
    return {"summary": summary, "entities": entities}

def summarize(text: str) -> str:
    response = client.chat.completions.create(...)
    return response.choices[0].message.content

def extract_entities(text: str) -> list:
    response = client.chat.completions.create(...)
    return parse_entities(response)

Environment Variables

Store keys in environment variables:
# .env
OPENAI_API_KEY=sk-...
MUXX_API_KEY=muxx_sk_live_...
from muxx import Muxx
from openai import OpenAI

# Both read from environment automatically
muxx = Muxx()
client = muxx.wrap(OpenAI())

Rollback Plan

If you need to rollback:
  1. Gateway: Remove base_url and headers
  2. SDK: Remove muxx.wrap() call
Your application will work as before, just without Muxx logging.

Gradual Migration

Migrate gradually by project or feature:
  1. Start with non-critical features
  2. Verify logs appear in dashboard
  3. Expand to more features
  4. Enable for production

Troubleshooting

Logs not appearing

  1. Check API key is correct
  2. Verify project has provider keys configured
  3. Check network allows gateway.muxx.dev

Increased latency

  1. Gateway adds minimal overhead
  2. Enable caching for repeated queries
  3. Check if rate limited