Title: Portkey integration code and tests by priyankinfinnov · Pull Request #583 · openlayer-ai/openlayer-python · GitHub
Open Graph Title: Portkey integration code and tests by priyankinfinnov · Pull Request #583 · openlayer-ai/openlayer-python
X Title: Portkey integration code and tests by priyankinfinnov · Pull Request #583 · openlayer-ai/openlayer-python
Description: Pull Request Summary Added tracing support for Portkey AI Gateway, enabling automatic monitoring of all LLM completions routed through Portkey's unified interface. This integration allows users to trace and monitor completions across 100+ LLM providers supported by Portkey through a single interface, with full support for both streaming and non-streaming completions. Changes Implement portkey_tracer.py with instance-level patching of Portkey's chat.completions.create method Add support for streaming and non-streaming completion tracing Implement provider detection from Portkey headers, response metadata, and model name heuristics Extract Portkey-specific metadata (trace IDs, cache status, retry counts) Add usage and cost calculation with fallback estimation for streaming completions Implement metadata extraction that works across different Portkey SDK versions Add comprehensive test suite covering all major functionality (test_portkey_integration.py) Export trace_portkey() function in lib/__init__.py for public API Add example notebook demonstrating Portkey tracing usage (portkey_tracing.ipynb) Context Portkey AI Gateway provides a unified interface to call 100+ LLM APIs using the same OpenAI-compatible input/output format. This integration enables Openlayer users to monitor and trace all their LLM completions routed through Portkey, regardless of the underlying provider (OpenAI, Anthropic, Google, Meta, Mistral, Cohere, etc.). The implementation follows a similar pattern to the existing LiteLLM integration but uses instance-level patching (via __init__ wrapping) to handle Portkey's lazy initialization of the chat attribute. This approach ensures compatibility across different Portkey SDK versions and handles edge cases gracefully. Key features: Automatic provider detection from Portkey headers or response metadata Portkey-specific metadata capture (trace IDs, cache hits/misses, retry attempts) Sensitive header redaction (API keys, virtual keys) Support for tool calls and function calls Cost calculation with provider-specific heuristics Testing Unit tests Manual testing Unit Tests: Comprehensive test suite with 20+ test cases covering: Import handling when Portkey is unavailable Instance-level patching behavior Streaming and non-streaming completion handling Provider detection (headers, metadata, model name fallbacks) Metadata extraction (client headers, response headers, unit metadata) Usage extraction from responses and chunks Cost and token calculation for streaming completions Output parsing (content, function calls, tool calls) Trace argument creation and provider metadata passing Manual Testing: Verified with example notebook demonstrating: Basic completion tracing Tool calling with function definitions Automatic metadata capture Provider detection across different models After merge We must update public documentation to add a page for Portkey Integration with appropriate details, logo, examples and links etc.
Open Graph Description: Pull Request Summary Added tracing support for Portkey AI Gateway, enabling automatic monitoring of all LLM completions routed through Portkey's unified interface. This integration allows users...
X Description: Pull Request Summary Added tracing support for Portkey AI Gateway, enabling automatic monitoring of all LLM completions routed through Portkey's unified interface. This integration allows u...
Opengraph URL: https://github.com/openlayer-ai/openlayer-python/pull/583
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:7a27af3c-a044-3a2f-c4f7-fe1d071a8e45 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 978E:2C39D7:7D987F:ADAF1F:698E0B98 |
| html-safe-nonce | d5727becd893742c8345fdfb98472914e145088c9964ae3356ae8237b37f2171 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzhFOjJDMzlENzo3RDk4N0Y6QURBRjFGOjY5OEUwQjk4IiwidmlzaXRvcl9pZCI6IjczNzUyNzA4MTY4NjUxOTI4NTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b845781bf081db433e705aafe34c4f56d90af153a5be48d55868069e6b7b9842 |
| hovercard-subject-tag | pull_request:3188446000 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/openlayer-ai/openlayer-python/pull/583/files |
| twitter:image | https://avatars.githubusercontent.com/u/15610225?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/15610225?s=400&v=4 |
| og:image:alt | Pull Request Summary Added tracing support for Portkey AI Gateway, enabling automatic monitoring of all LLM completions routed through Portkey's unified interface. This integration allows users... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 70a88bfe6d9639434ae7f5a46d15c336b8884978a51526bc55fc57d848f1e3c1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/openlayer-ai/openlayer-python git https://github.com/openlayer-ai/openlayer-python.git |
| octolytics-dimension-user_id | 78678711 |
| octolytics-dimension-user_login | openlayer-ai |
| octolytics-dimension-repository_id | 340524200 |
| octolytics-dimension-repository_nwo | openlayer-ai/openlayer-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 340524200 |
| octolytics-dimension-repository_network_root_nwo | openlayer-ai/openlayer-python |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2519b16db5550494a653f9a8837c14ef7df80804 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width