Skip to main content
Portkey is an LLM gateway. You send chat completions through a single client, and Portkey routes them to the provider behind a model slug. If you are building an AI system with Portkey and want to evaluate it, you can use the Python SDK to make Openlayer part of your workflow. This integration is Python-only — the TypeScript SDK does not include a Portkey tracer. This guide shows how you can trace Portkey chat.completions.create calls and publish them to Openlayer.

Evaluating Portkey completions

You can set up Openlayer tests to evaluate your Portkey completions in monitoring. Instrument your code so each request is traced and published to the platform. Install the Portkey SDK alongside Openlayer:
Traced calls show up as Portkey Chat Completion steps. If a Portkey call is just one step of your AI system, use the snippets on this page together with tracing. In that case, the completion is added as a step of a larger trace. After requests are continuously published and logged by Openlayer, you can create tests that run at a regular cadence on top of them. Refer to the Monitoring overview for details on Openlayer’s monitoring mode, or to the Tracing guide to understand how to trace more complex systems.

Auto-instrumentation with init()

init() auto-instruments installed LLM SDKs, including Portkey when the portkey_ai package is present (registry name "portkey"). Call it before you create a Portkey client:
Once the code is instrumented, Portkey chat completions are automatically published to Openlayer. If you navigate to the “Data” page of your Openlayer data source, you can see the traces for each request.

Manual trace_portkey()

If you prefer not to auto-instrument every installed SDK, call trace_portkey() before you use Portkey. Tracing then happens automatically on chat.completions.create:
You still need OPENLAYER_API_KEY and OPENLAYER_INFERENCE_PIPELINE_ID in the environment. The optional inference_id kwarg is popped before the request is sent to Portkey.

What is captured

Openlayer records streaming and non-streaming chat.completions.create calls. For each Portkey Chat Completion step, the tracer captures:
  • start_time
  • end_time
  • latency
  • tokens
  • prompt_tokens
  • completion_tokens
  • model
  • model_parameters
  • raw_output
  • inputs
  • Portkey-specific metadata (base URL, x-portkey-* headers if available)