Service Endpoints
Types for configuring multi-backend service endpoints.
Abstract Types
UniLM.ServiceEndpoint — Type
ServiceEndpointAbstract 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 ServiceGEMINIOpenAIServiceEndpoint— Google Gemini via OpenAI-compatible endpointGEMINIServiceEndpoint— Google Gemini native generateContent APIANTHROPICServiceEndpoint— Anthropic (Claude) native Messages APIGenericOpenAIEndpoint— any OpenAI-compatible provider (Ollama, Mistral, vLLM, etc.)
UniLM.OpenAIWireEndpoint — Type
OpenAIWireEndpoint <: ServiceEndpointAbstract 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.
Built-in Endpoints
UniLM.OPENAIServiceEndpoint — Type
OpenAI API service endpoint (default). Requires OPENAI_API_KEY env variable.
UniLM.AZUREServiceEndpoint — Type
Azure OpenAI Service endpoint. Requires AZURE_OPENAI_BASE_URL, AZURE_OPENAI_API_KEY, and AZURE_OPENAI_API_VERSION env variables.
UniLM.GEMINIServiceEndpoint — Type
Native Google Gemini generateContent API (x-goog-api-key; model in URL). Requires GEMINI_API_KEY.
UniLM.GEMINIOpenAIServiceEndpoint — Type
Google Gemini endpoint (OpenAI-compatible). Requires GEMINI_API_KEY env variable.
UniLM.ANTHROPICServiceEndpoint — Type
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.
Generic Endpoint
UniLM.GenericOpenAIEndpoint — Type
GenericOpenAIEndpoint <: OpenAIWireEndpointConfigurable 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")UniLM.ServiceEndpointSpec — Type
ServiceEndpointSpecType alias accepting both marker types (OPENAIServiceEndpoint) and instances (GenericOpenAIEndpoint(...)). Used as the type of service fields.
UniLM.OllamaEndpoint — Function
OllamaEndpoint(; base_url="http://localhost:11434") -> GenericOpenAIEndpointPre-configured endpoint for Ollama local server.
UniLM.MistralEndpoint — Function
MistralEndpoint(; api_key=ENV["MISTRAL_API_KEY"]) -> GenericOpenAIEndpointPre-configured endpoint for Mistral AI API.
UniLM.DeepSeekEndpoint — Type
DeepSeekEndpoint <: OpenAIWireEndpointPre-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).
Configuration
Each endpoint reads its configuration from environment variables:
OpenAI (default)
| Variable | Description |
|---|---|
OPENAI_API_KEY | Your OpenAI API key |
Azure OpenAI
| Variable | Description |
|---|---|
AZURE_OPENAI_BASE_URL | Azure endpoint base URL |
AZURE_OPENAI_API_KEY | Azure API key |
AZURE_OPENAI_API_VERSION | API version (e.g. 2024-12-01-preview) |
AZURE_OPENAI_DEPLOY_NAME_GPT_5_2 | Deployment name for gpt-5.2 |
Google Gemini
| Variable | Description |
|---|---|
GEMINI_API_KEY | Your Gemini API key |
Both GEMINIServiceEndpoint (native generateContent) and GEMINIOpenAIServiceEndpoint (the OpenAI-compat shim) read GEMINI_API_KEY.
Anthropic (Claude)
| Variable | Description |
|---|---|
ANTHROPIC_API_KEY | Your 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")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-deploySelecting 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