{"id":24163,"library":"openinference-instrumentation-portkey","title":"OpenInference Portkey AI Instrumentation","description":"OpenInference instrumentation for Portkey AI gateway, enabling tracing of LLM calls made via Portkey. Version 0.1.8 supports Python 3.10-3.14. Part of the Arize AI OpenInference ecosystem for observability of AI applications.","status":"active","version":"0.1.8","language":"python","source_language":"en","source_url":"https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-portkey","tags":["portkey","llm","observability","opentelemetry","tracing","openinference"],"install":[{"cmd":"pip install openinference-instrumentation-portkey","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Base OpenInference instrumentation package providing core tracing APIs","package":"openinference-instrumentation","optional":false},{"reason":"Portkey AI client SDK - the instrumented library","package":"portkey-ai","optional":false},{"reason":"OpenTelemetry API for creating spans and traces","package":"opentelemetry-api","optional":false},{"reason":"Used for monkey-patching Portkey methods (compatible with wrapt 2.x)","package":"wrapt","optional":false}],"imports":[{"note":"Correct import for the instrumentor class","wrong":"","symbol":"PortkeyInstrumentor","correct":"from openinference_instrumentation_portkey import PortkeyInstrumentor"}],"quickstart":{"code":"import os\nfrom openinference_instrumentation_portkey import PortkeyInstrumentor\nfrom opentelemetry import trace as trace_api\n\n# Set up a TracerProvider (e.g., ConsoleSpanExporter for debugging)\nfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import SimpleSpanProcessor\n\ntrace_provider = TracerProvider()\ntrace_provider.add_span_processor(\n    SimpleSpanProcessor(OTLPSpanExporter(endpoint=os.environ.get(\"OTEL_ENDPOINT\", \"http://localhost:4318/v1/traces\")))\n)\ntrace_api.set_tracer_provider(trace_provider)\n\n# Instrument Portkey\nPortkeyInstrumentor().instrument()\n\n# Now use Portkey normally - calls will be traced\nfrom portkey_ai import Portkey\n\nclient = Portkey(api_key=os.environ.get(\"PORTKEY_API_KEY\", \"\"))\nresponse = client.completions.create(prompt=\"Hello\", model=\"gpt-3.5-turbo\")\nprint(response.choices[0].text)\n","lang":"python","description":"Initialize tracing by setting up an OpenTelemetry TracerProvider and calling PortkeyInstrumentor().instrument() before any Portkey usage."},"warnings":[{"fix":"Ensure the .instrument() call happens at module-level before any Portkey usage, ideally right after setting up OpenTelemetry.","message":"Instrumentation must be called before any Portkey client is created. If you import or instantiate Portkey before calling .instrument(), traces will not be captured.","severity":"gotcha","affected_versions":"all"},{"fix":"Set a global tracer provider via trace_api.set_tracer_provider(TracerProvider()) and add a span processor with an exporter.","message":"If no TracerProvider is set, instrumentation silently fails (no spans emitted). Ensure opentelemetry-api and a TracerProvider (e.g., from opentelemetry-sdk) are configured.","severity":"gotcha","affected_versions":"all"},{"fix":"Install or upgrade wrapt: pip install 'wrapt>=1.14'","message":"This package requires wrapt. If you have an older version of wrapt or wrapt is missing, you may see import errors. Versions >=1.14 are recommended.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Verify installation: pip install openinference-instrumentation-portkey. Check your Python environment and reinstall if needed.","cause":"The package may not be installed correctly, or you are using an older version that had a different export.","error":"ImportError: cannot import name 'PortkeyInstrumentor' from 'openinference_instrumentation_portkey'"},{"fix":"Ensure you have the latest version: pip install --upgrade openinference-instrumentation-portkey","cause":"Similar to above; the module exists but the instrumentor class is not exported (possible version mismatch).","error":"AttributeError: module 'openinference_instrumentation_portkey' has no attribute 'PortkeyInstrumentor'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}