René's URL Explorer Experiment


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

direct link

Domain: patch-diff.githubusercontent.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:7a27af3c-a044-3a2f-c4f7-fe1d071a8e45
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id978E:2C39D7:7D987F:ADAF1F:698E0B98
html-safe-nonced5727becd893742c8345fdfb98472914e145088c9964ae3356ae8237b37f2171
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzhFOjJDMzlENzo3RDk4N0Y6QURBRjFGOjY5OEUwQjk4IiwidmlzaXRvcl9pZCI6IjczNzUyNzA4MTY4NjUxOTI4NTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacb845781bf081db433e705aafe34c4f56d90af153a5be48d55868069e6b7b9842
hovercard-subject-tagpull_request:3188446000
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/openlayer-ai/openlayer-python/pull/583/files
twitter:imagehttps://avatars.githubusercontent.com/u/15610225?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/15610225?s=400&v=4
og:image:altPull 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_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None70a88bfe6d9639434ae7f5a46d15c336b8884978a51526bc55fc57d848f1e3c1
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/openlayer-ai/openlayer-python git https://github.com/openlayer-ai/openlayer-python.git
octolytics-dimension-user_id78678711
octolytics-dimension-user_loginopenlayer-ai
octolytics-dimension-repository_id340524200
octolytics-dimension-repository_nwoopenlayer-ai/openlayer-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id340524200
octolytics-dimension-repository_network_root_nwoopenlayer-ai/openlayer-python
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release2519b16db5550494a653f9a8837c14ef7df80804
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenlayer-ai%2Fopenlayer-python%2Fpull%2F583%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenlayer-ai%2Fopenlayer-python%2Fpull%2F583%2Ffiles
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=openlayer-ai%2Fopenlayer-python
Reloadhttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files
Reloadhttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files
Reloadhttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files
openlayer-ai https://patch-diff.githubusercontent.com/openlayer-ai
openlayer-pythonhttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fopenlayer-ai%2Fopenlayer-python
Fork 2 https://patch-diff.githubusercontent.com/login?return_to=%2Fopenlayer-ai%2Fopenlayer-python
Star 16 https://patch-diff.githubusercontent.com/login?return_to=%2Fopenlayer-ai%2Fopenlayer-python
Code https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python
Issues 0 https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/issues
Pull requests 4 https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pulls
Actions https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/actions
Projects 0 https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/projects
Security 0 https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/security
Insights https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pulse
Code https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python
Issues https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/issues
Pull requests https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pulls
Actions https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/actions
Projects https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/projects
Security https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/security
Insights https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pulse
Sign up for GitHub https://patch-diff.githubusercontent.com/signup?return_to=%2Fopenlayer-ai%2Fopenlayer-python%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://patch-diff.githubusercontent.com/login?return_to=%2Fopenlayer-ai%2Fopenlayer-python%2Fissues%2Fnew%2Fchoose
priyankinfinnovhttps://patch-diff.githubusercontent.com/priyankinfinnov
openlayer-ai:mainhttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/tree/main
priyankinfinnov:portkey-integrationhttps://patch-diff.githubusercontent.com/priyankinfinnov/openlayer-python/tree/portkey-integration
Conversation 0 https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583
Commits 1 https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/commits
Checks 3 https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/checks
Files changed https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files
Please reload this pagehttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files
Portkey integration code and tests https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#top
Show all changes 1 commit https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files
03c36e1 portkey integration code and tests priyankinfinnov Jan 19, 2026 https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/commits/03c36e1d5a94ceb626c193044205fdad1868fa24
Clear filters https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files
Please reload this pagehttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files
Please reload this pagehttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files
portkey_tracing.ipynb https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#diff-76f04d97004f7fe4c0abaece1f65e04dc578e811afbc50b4cc84a6ec4ccc1025
__init__.py https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#diff-f547e99fc2851b54e297af4f92c560a7943235bc2ea489e4a3f91cb06eab5f3b
portkey_tracer.py https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#diff-15d9532500a1f7832919d8fc70b67081eee9c103ae9333d02df0909ebd410b7c
test_integration_conditional_imports.py https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#diff-8daadf98d5e756d05e021b81af6cbcaaf6c532e9ce2786078498e5ee35b2be04
test_portkey_integration.py https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#diff-f10415fe09a594154370acd741a7f00797454a66a19e18fe4adc00b6218cddd9
examples/tracing/portkey/portkey_tracing.ipynbhttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#diff-76f04d97004f7fe4c0abaece1f65e04dc578e811afbc50b4cc84a6ec4ccc1025
View file https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/blob/03c36e1d5a94ceb626c193044205fdad1868fa24/examples/tracing/portkey/portkey_tracing.ipynb
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/{{ revealButtonHref }}
src/openlayer/lib/__init__.pyhttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#diff-f547e99fc2851b54e297af4f92c560a7943235bc2ea489e4a3f91cb06eab5f3b
View file https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/blob/03c36e1d5a94ceb626c193044205fdad1868fa24/src/openlayer/lib/__init__.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/{{ revealButtonHref }}
https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#diff-f547e99fc2851b54e297af4f92c560a7943235bc2ea489e4a3f91cb06eab5f3b
https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#diff-f547e99fc2851b54e297af4f92c560a7943235bc2ea489e4a3f91cb06eab5f3b
https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#diff-f547e99fc2851b54e297af4f92c560a7943235bc2ea489e4a3f91cb06eab5f3b
https://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files#diff-f547e99fc2851b54e297af4f92c560a7943235bc2ea489e4a3f91cb06eab5f3b
Please reload this pagehttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files
Please reload this pagehttps://patch-diff.githubusercontent.com/openlayer-ai/openlayer-python/pull/583/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.