Skip to content

Comprehensive Provider Abstraction Layer Needed #33

@ebowwa

Description

@ebowwa

Context

Following the resolution of #32, which revealed deeper architectural needs beyond the immediate system_instruction fix, this issue tracks the comprehensive work needed to achieve true provider abstraction in ai-proxy-core.

Problem Statement

While fixing #32, we discovered that parameter handling is inconsistent across providers. The library currently requires developers to understand provider-specific differences, defeating the purpose of an abstraction layer.

Current Gaps

1. Parameter Normalization

  • Temperature: Different ranges (0-1 vs 0-2)
  • Token limits: max_tokens vs max_output_tokens vs max_new_tokens
  • Response formats: JSON mode implementations vary
  • Stop sequences: Different parameter names and behaviors
  • Sampling parameters: top_p, top_k availability varies

2. Feature Parity Issues

  • Tool/Function calling: Completely different implementations
  • Streaming: Inconsistent response formats
  • Vision capabilities: Not all providers support images
  • Embeddings: Different dimensionality and models
  • Safety settings: Provider-specific implementations

3. Error Handling

  • Different error formats and codes
  • Inconsistent rate limiting responses
  • No unified retry strategy
  • Missing automatic failover

4. Missing Abstractions

# What we have:
system_instruction="Be helpful"  # Works after v0.4.3

# What we need:
response = await client.create_completion(
    messages=messages,
    model="auto",  # Provider selection based on requirements
    temperature=0.7,  # Normalized across all providers
    json_mode=True,  # Unified JSON response handling
    safety="medium",  # Abstracted safety levels
    retry_strategy="exponential",
    fallback_providers=["openai", "gemini", "ollama"],
    capabilities_required=["streaming", "tools", "vision"]
)

Proposed Solution

Phase 1: Discovery & Documentation

  • Audit ALL parameters across providers
  • Create compatibility matrix
  • Document provider capabilities
  • Identify normalization strategies

Phase 2: Core Abstractions

  • Implement parameter normalization layer
  • Create unified error handling
  • Build capability detection system
  • Add provider selection logic

Phase 3: Advanced Features

  • Automatic failover between providers
  • Cost optimization routing
  • Performance-based selection
  • Feature fallback strategies

Phase 4: Testing & Validation

  • Cross-provider integration tests
  • Performance benchmarks
  • Error scenario testing
  • Real-world usage validation

Success Criteria

  1. Zero provider-specific code in applications using the library
  2. Automatic handling of provider differences
  3. Seamless failover when providers are unavailable
  4. Consistent behavior across all providers
  5. Clear capability reporting for feature availability

Technical Design Considerations

  1. Backwards compatibility: Existing code must continue working
  2. Progressive enhancement: Advanced features optional
  3. Performance: Abstraction shouldn't add significant overhead
  4. Extensibility: Easy to add new providers
  5. Debugging: Clear visibility into provider selection and transformations

Related Issues

Questions for Discussion

  1. Should provider-specific features be exposed or hidden?
  2. How do we handle features that only some providers support?
  3. What's the right balance between abstraction and control?
  4. Should we support provider-specific escape hatches?

This is a significant architectural evolution that will make ai-proxy-core truly provider-agnostic. Looking for community input on priorities and approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions