Skip to content

[Feature] Merge Provider Configuration Metadata into Hook ContextΒ #1427

@shubhamdeodia

Description

@shubhamdeodia

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

Your Twitter/LinkedIn

https://www.linkedin.com/in/shubham-deodia/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions