-
Notifications
You must be signed in to change notification settings - Fork 806
Open
Labels
Description
What Would You Like to See with the Gateway?
π Summary
Allow hooks to access metadata defined in provider configurations (like x-portkey-config) by merging it with the existing hook context metadata. Currently, hooks can only access metadata passed via HTTP headers, making configuration-based metadata completely inaccessible.
π― Motivation
Current Problem
When using Portkey with rich provider configurations, metadata defined in configuration files is invisible to hooks:
// conf.json - This metadata is INACCESSIBLE to hooks
{
"targets": [
{
"provider": "azure-openai",
"resource_name": "openai-east",
"metadata": {
"region": "eastus2",
"backend": "BACKEND_2",
"deployment_tier": "platform_gpu",
"priority": 1,
"compliance_zone": "us"
}
}
]
}Hook Context Reality:
// In hook plugins - metadata is empty!
console.log(context.metadata); // {} - EMPTY!Why This Matters
- β No region-based logic - Can't implement compliance rules per region
- β No backend awareness - Can't optimize based on backend type
- β No priority handling - Can't implement tier-based rate limiting
- β Configuration duplication - Must pass metadata via both config AND headers
π Proposed Solution
Simple Metadata Merging
Merge provider configuration metadata into the hook context's metadata object:
// Current implementation
context.metadata = headerMetadata; // Only HTTP headers
// Proposed implementation
context.metadata = {
...providerOption.metadata, // Configuration metadata
...headerMetadata // HTTP headers (takes precedence)
};π Benefits
β For Developers
- Rich Context: Access configuration metadata in hooks
- Simplified Setup: No need to duplicate metadata in headers
- Better Logic: Implement sophisticated provider-aware hooks
- Clean Architecture: Single source of truth for metadata
β For Operations
- Environment Awareness: Different behavior per environment
- Cost Tracking: Track usage by cost center/team
- Performance Optimization: Tier-based optimizations
- Compliance: Automatic regional compliance
β For Implementation
- Zero Breaking Changes: Existing hooks continue to work
- Simple Implementation: Just merge two objects
- Backward Compatible: Header metadata still supported
- Performance: Minimal overhead
Context for your Request
We are evaluating Portkey in our org and this is needed to continue with POC