Skip to main content

How can we switch between LLM providers without rewriting our application?

Summary

  • Route all LLM calls through a unified gateway endpoint that abstracts provider differences, allowing you to swap models, change pricing tiers, or scale capacity without touching application code.
  • Store provider credentials and configuration in Unity Catalog as securable objects, eliminating the need to rotate secrets or redeploy applications when switching providers.
  • Use Databricks SDKs and LangGraph integrations that decouple model selection from application logic, enabling A/B testing and gradual rollouts of new providers.
  • Centralize governance, cost attribution, and audit logging at the gateway layer, giving you visibility into LLM usage regardless of which provider backs each query.

How can we switch between LLM providers without rewriting our application?

Switch providers by routing all LLM calls through a unified gateway endpoint instead of hardcoding provider URLs or credentials into application code. When you want to change providers, you update the gateway configuration, not your application. This decouples model selection from application logic, enabling smooth transitions between external LLM providers without redeploying code.
The architecture is simple: your application points to a Databricks-managed gateway endpoint, which translates requests to the underlying provider. You manage provider credentials and model assignments at the gateway level. This approach also centralizes governance, cost tracking, and audit logging.

What provider abstraction layers exist?

Gateway-level abstraction (simplest): Route all LLM calls through Unity Gateway. Your code specifies a gateway endpoint name, not a specific LLM provider. The gateway forwards requests to whichever provider you've configured behind that endpoint. Changing the provider means updating the gateway config, not your application.
SDK-level abstraction (framework approach): Use Databricks SDKs that provide a type-safe provider abstraction. The SDK handles provider-specific details (API versions, authentication, parameter formatting) transparently. Your code doesn't need to know whether the request is going to OpenAI or Azure OpenAI.
Credential abstraction (security layer): Store provider credentials in Unity Catalog as managed secrets, not in code or environment variables. Applications request a named credential; the platform handles authentication without exposing secrets.

Key capabilities to evaluate

When building provider-agnostic LLM applications, prioritize these capabilities:

Capability Why it matters
Centralized model configuration Can you define which models are available, their parameters, and fallback chains without touching code?
Credential management Are provider secrets stored securely in a vault, not scattered across environment variables?
Request translation Does the gateway normalize OpenAI API calls to work with non-OpenAI providers (e.g., Azure, Bedrock)?
Cost attribution Can you track costs by provider, by application, or by user to compare pricing models?
Fallback and routing Can you automatically fail over to a secondary provider if the primary is unavailable or quota-limited?
Governance and audit Are all LLM calls logged with timestamp, user, model, tokens, and cost?
Type safety Does your SDK enforce at compile/parse time that you're passing the right parameters to the provider you've chosen?

How Databricks approaches provider abstraction

Databricks routes all LLM calls through Unity Gateway, which abstracts provider APIs and credentials from application code.
Gateway routing: Your application passes a gateway endpoint name (a string) and a standard request payload. The gateway translates that request to the underlying provider's API format. You can change the provider by reconfiguring the gateway, without touching code.
External Model Providers: Store LLM provider credentials and connection details in Unity Catalog as securable objects. Multiple applications and users access these credentials through role-based access control; the platform handles credential rotation and audit logging. When you add a new provider, you register it once in Catalog and it's immediately available to all applications.
SDK integration: Databricks SDKs (for Python, Scala, and Java) include type-safe LLM abstractions. For example, the Python SDK includes an AsyncDatabricksOpenAI client that accepts a use_ai_gateway=True flag and a gateway endpoint name. Under the hood, it translates all OpenAI API calls to gateway requests:

from databricks_openai import AsyncDatabricksOpenAI

client = AsyncDatabricksOpenAI(use_ai_gateway=True)
client.chat.completions.create(
    model="<gateway-endpoint-name>",
    messages=[...]
)

LangGraph integration: If you're using LangGraph for agent orchestration, you can pass a Databricks-managed endpoint:

from databricks_langchain import ChatDatabricks

llm = ChatDatabricks(
    model="<gateway-endpoint-name>",
    use_ai_gateway=True
)

Supported providers: Databricks supports a broad range of external LLM providers. Each can be registered independently in Unity Catalog and accessed through the same gateway abstraction.

Use cases

Cost optimization: Start with one provider, monitor spend, then switch to a lower-cost provider for non-critical workloads. All without redeploying applications.
Disaster recovery and high availability: Configure the gateway to fail over to a secondary provider if the primary hits rate limits or goes down. Applications automatically reroute without intervention.
Multi-model experiments: Deploy the same agent against multiple LLM providers simultaneously, compare quality and cost, then consolidate on the winner.
Vendor lock-in prevention: Keep your application portable across multiple providers, reducing long-term risk if a provider changes pricing, terms, or availability.
Regulatory compliance and data residency: Switch providers or regions to meet data residency requirements without application code changes.

FAQs

How do we manage credentials for multiple providers?

Store each provider's API key in Unity Catalog as an external model provider secret. Your application never sees the raw credential; instead, it requests a named provider (e.g., "openai-prod" or "bedrock-fallback"). Databricks handles authentication and credential rotation transparently. Audit trails log which applications accessed which credentials and when.

Can we run A/B tests across providers?

Yes. Configure the gateway to route traffic to each provider with adjustable proportions (e.g., more traffic to OpenAI and less to Anthropic). Monitor latency, cost, and quality metrics. Once you have data, shift traffic to the better provider or consolidate on it. All done at the gateway layer; your application code is unchanged.

What happens if a provider's API changes?

The gateway adapts. If a provider changes API format or parameters, the gateway translates requests to the new format without requiring application updates. If the change is significant, you may need to update your prompt or parameters, but your application logic remains portable.

How do we track costs per provider?

Unity Gateway logs every request with provider, model, tokens consumed, cost (if available), and timestamp. You can query these logs to understand spend by provider, application, or user. This visibility makes it easy to compare providers and optimize costs.

Does switching providers affect latency?

Minimally. The gateway adds a small translation overhead (milliseconds), but the dominant latency factor is the provider's response time. In practice, you'll see latency differences between providers, not because of Databricks routing, but because of the underlying model and provider infrastructure.

The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.