Add HoneyHive observability to your Portkey AI gateway applications
Portkey is an AI gateway that provides a unified API to access 1,600+ LLMs with features like fallbacks, load balancing, caching, and budget limits. Since Portkey exposes an OpenAI-compatible API, HoneyHive automatically traces all requests routed through the gateway via the OpenAI instrumentor.
Add HoneyHive tracing to your Portkey-routed app. Initialize HoneyHive with the OpenAI instrumentor, then point your OpenAI client to Portkey’s gateway. All completions are automatically traced regardless of the underlying provider.
To see where to initialize the tracer for your environment, including AWS Lambda and long-running servers, see Tracer Initialization.
import osfrom openai import OpenAIfrom portkey_ai import PORTKEY_GATEWAY_URLfrom honeyhive import HoneyHiveTracerfrom openinference.instrumentation.openai import OpenAIInstrumentortracer = HoneyHiveTracer.init(api_key=os.getenv("HH_API_KEY"))OpenAIInstrumentor().instrument(tracer_provider=tracer.provider)# Point OpenAI client to Portkey's gatewayclient = OpenAI( api_key=os.getenv("PORTKEY_API_KEY"), base_url=PORTKEY_GATEWAY_URL)# Use @provider-slug/model format from Portkey's Model Catalogresponse = client.chat.completions.create( model="@openai-prod/gpt-4o-mini", messages=[{"role": "user", "content": "Hello, world!"}])print(response.choices[0].message.content)
The @provider-slug/model format routes requests to the correct provider. Set up providers in Portkey’s Model Catalog by adding your provider credentials and naming the provider (e.g., openai-prod). The slug becomes @openai-prod.
Use a Portkey config to define fallback or load-balancing rules. Create the config in the Portkey dashboard and pass its ID via the config header. HoneyHive traces whichever provider handles the request:
Check the model slug - Use the @provider-slug/model-name format (e.g., @openai-prod/gpt-4o-mini). The provider slug must match a provider you configured in Model Catalog
Verify model name - Use the model name expected by the target provider (e.g., gpt-4o-mini for OpenAI, claude-sonnet-4-5-20250929 for Anthropic)
If you use both a Portkey client and a direct OpenAI client in the same app, both will be traced by the same instrumentor. Use HoneyHive’s @trace decorator to group related calls into named spans for clarity.