-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathgateway.py
More file actions
43 lines (29 loc) · 1.19 KB
/
gateway.py
File metadata and controls
43 lines (29 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Gateway client utilities for HUD inference gateway."""
from __future__ import annotations
from typing import Any
def build_gateway_client(provider: str) -> Any:
"""Build a client configured for HUD gateway routing.
Args:
provider: Provider name ("anthropic", "openai", "gemini", etc.)
Returns:
Configured async client for the provider.
"""
from hud.settings import settings
provider = provider.lower()
if provider == "anthropic":
from anthropic import AsyncAnthropic
return AsyncAnthropic(api_key=settings.api_key, base_url=settings.hud_gateway_url)
if provider == "gemini":
from google import genai
from google.genai.types import HttpOptions
return genai.Client(
api_key="PLACEHOLDER",
http_options=HttpOptions(
api_version="v1beta",
base_url=settings.hud_gateway_url,
headers={"Authorization": f"Bearer {settings.api_key}"},
),
)
# OpenAI-compatible (openai, azure, together, groq, fireworks, etc.)
from openai import AsyncOpenAI
return AsyncOpenAI(api_key=settings.api_key, base_url=settings.hud_gateway_url)