Service Endpoints

Types for configuring multi-backend service endpoints.

Abstract Types

UniLM.ServiceEndpointType
ServiceEndpoint

Abstract supertype for LLM service backends. Subtypes control URL routing and authentication.

OpenAI-compatible backends subtype OpenAIWireEndpoint (itself a subtype of ServiceEndpoint) to inherit the chat request/response encoding and SSE handling; backends with a native wire (Anthropic, Gemini) subtype ServiceEndpoint directly and implement the wire seam (encode_request/decode_response/handle_sse_event!) themselves.

Built-in subtypes:

  • OPENAIServiceEndpoint — OpenAI API (default)
  • AZUREServiceEndpoint — Azure OpenAI Service
  • GEMINIOpenAIServiceEndpoint — Google Gemini via OpenAI-compatible endpoint
  • GEMINIServiceEndpoint — Google Gemini native generateContent API
  • ANTHROPICServiceEndpoint — Anthropic (Claude) native Messages API
  • GenericOpenAIEndpoint — any OpenAI-compatible provider (Ollama, Mistral, vLLM, etc.)
source
UniLM.OpenAIWireEndpointType
OpenAIWireEndpoint <: ServiceEndpoint

Abstract supertype for backends that speak the OpenAI-compatible chat wire. Subtypes inherit the OpenAI Chat Completions request/response encoding (encode_request/decode_response) and the default SSE stream handling (handle_sse_event!) for free, so a new OpenAI-compatible provider defines only get_url and auth_header (plus, optionally, the _api_base_url pattern that routes the Responses/agentic surface).

Backends that speak a genuinely different wire (Anthropic's Messages API, Gemini's native generateContent) subtype ServiceEndpoint directly and additionally implement encode_request, decode_response, and handle_sse_event!. A bare ServiceEndpoint subtype that omits those methods fails with a MethodError at call time rather than silently emitting OpenAI-shaped requests to a foreign API.

Built-in OpenAI-wire subtypes: OPENAIServiceEndpoint, AZUREServiceEndpoint, GEMINIOpenAIServiceEndpoint, GenericOpenAIEndpoint, DeepSeekEndpoint.

source

Built-in Endpoints

UniLM.AZUREServiceEndpointType

Azure OpenAI Service endpoint. Requires AZURE_OPENAI_BASE_URL, AZURE_OPENAI_API_KEY, and AZURE_OPENAI_API_VERSION env variables.

source
UniLM.ANTHROPICServiceEndpointType

Anthropic (Claude) native Messages API endpoint. Requires the ANTHROPIC_API_KEY env variable. Native wire format (content blocks, top-level system, user/assistant roles) — NOT OpenAI-compatible.

source

Generic Endpoint

UniLM.GenericOpenAIEndpointType
GenericOpenAIEndpoint <: OpenAIWireEndpoint

Configurable endpoint for any OpenAI-compatible API provider. Supports Chat Completions, Embeddings, and (where the provider implements it) the Responses API.

Fields

  • base_url::String: Base URL without trailing slash (e.g., "http://localhost:11434")
  • api_key::String: API key for Bearer auth. Use "" for local servers with no auth.

Example

# Ollama (local)
chat = Chat(service=GenericOpenAIEndpoint("http://localhost:11434", ""), model="llama3.1")

# Mistral
chat = Chat(service=GenericOpenAIEndpoint("https://api.mistral.ai", ENV["MISTRAL_API_KEY"]),
            model="mistral-large-latest")
source
UniLM.ServiceEndpointSpecType
ServiceEndpointSpec

Type alias accepting both marker types (OPENAIServiceEndpoint) and instances (GenericOpenAIEndpoint(...)). Used as the type of service fields.

source
UniLM.OllamaEndpointFunction
OllamaEndpoint(; base_url="http://localhost:11434") -> GenericOpenAIEndpoint

Pre-configured endpoint for Ollama local server.

source
UniLM.DeepSeekEndpointType
DeepSeekEndpoint <: OpenAIWireEndpoint

Pre-configured endpoint for DeepSeek API. Supports chat completions, tool calling, FIM completion, and prefix completion.

FIM and prefix completion use the beta base URL (https://api.deepseek.com/beta).

source

Configuration

Each endpoint reads its configuration from environment variables:

OpenAI (default)

VariableDescription
OPENAI_API_KEYYour OpenAI API key

Azure OpenAI

VariableDescription
AZURE_OPENAI_BASE_URLAzure endpoint base URL
AZURE_OPENAI_API_KEYAzure API key
AZURE_OPENAI_API_VERSIONAPI version (e.g. 2024-12-01-preview)
AZURE_OPENAI_DEPLOY_NAME_GPT_5_2Deployment name for gpt-5.2

Google Gemini

VariableDescription
GEMINI_API_KEYYour Gemini API key

Both GEMINIServiceEndpoint (native generateContent) and GEMINIOpenAIServiceEndpoint (the OpenAI-compat shim) read GEMINI_API_KEY.

Anthropic (Claude)

VariableDescription
ANTHROPIC_API_KEYYour Anthropic API key

Azure Deployment Mapping

Azure requires model-to-deployment name mappings. Use add_azure_deploy_name! to register custom mappings:

UniLM.add_azure_deploy_name!Function
add_azure_deploy_name!(model::String, deploy_name::String)

Register an Azure OpenAI deployment for a given model name.

Example

add_azure_deploy_name!("gpt-5.2", "my-gpt52-deployment")
source
using UniLM

# Register a custom deployment for a specific model
UniLM.add_azure_deploy_name!("gpt-5.2", "my-gpt52-deploy")
println("Registered deployment: ", UniLM._MODEL_ENDPOINTS_AZURE_OPENAI["gpt-5.2"])
Registered deployment: /openai/deployments/my-gpt52-deploy

Selecting a Backend

Pass the service keyword to any request constructor:

chat = Chat(service=UniLM.AZUREServiceEndpoint, model="gpt-5.2")
println("Service: ", chat.service)
println("Model: ", chat.model)
Service: AZUREServiceEndpoint
Model: gpt-5.2