Add Otari as an OpenAI-compatible gateway provider

Merged
TB
17d ago
+457-10

Adds OtariProvider for Otari, Mozilla.ai's open-source LLM gateway (hosted at otari.ai or self-hosted).

from pydantic_ai import Agent

agent = Agent('otari:anthropic:claude-sonnet-5-5')  # OTARI_API_KEY, otari.ai US region
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.otari import OtariProvider

OpenAIChatModel('anthropic:claude-sonnet-5-5', provider=OtariProvider(region='eu'))
OpenAIChatModel('openai:gpt-5.2', provider=OtariProvider(base_url='http://localhost:8000/api/v1'))
  • OTARI_API_KEY for the key, with no fallback to OPENAI_API_KEY.
  • Endpoint: base_url or region ('us' or 'eu'), else OTARI_BASE_URL, else https://api.otari.ai/api/v1. Passing both region and base_url is a type error, and a UserError at runtime.
  • Model names are sent unchanged. provider:model and provider/model both select the family profile through vendor_family_model_profile, with overrides only for Otari ids that serve one vendor (azureopenai, gemini, moonshot). After a multi-vendor host (azure, bedrock, groq, together, vertexai, ...), a vendor/model id picks the family, as in groq:openai/gpt-oss-120b; other names get no family profile. A routing policy or alias name gets the default OpenAI-compatible profile.
  • Registered as otari in infer_provider_class, OpenAIChatCompatibleProvider and the special-token route table (not _EVERY_MODEL, since Otari also routes to closed models, as OpenRouter and Vercel do). When the name's provider part is a self-hosted server or an open-weight host (ollama, vllm, groq, together, ...), special tokens are escaped whatever the model's name.
  • Adding 'otari' to OpenAIChatCompatibleProvider needs an API-compatibility waiver (every value accepted before still is; only an exhaustive match on the alias sees a new member). Fork PRs can't change .github/, so its content is in a comment below for a maintainer to add.
  • Package label: this belongs under pkg:core, which I can't add from a fork.
  • Docs: an Otari section in docs/models/compatible-apis.md, a provider-directory row, the API reference entry, and the agent skill's prefix list.
  • Tests: tests/providers/test_otari.py (100% coverage of the module) and Otari entries in the shared provider-name, HTTP-client, special-token, agent re-entry, clai2 base-URL and examples tests.

Disclosure: I work on Otari at Mozilla.ai.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it. (None: additive only.)
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code


Summary by cubic

Adds the OtariProvider and StavProvider so agents can route through Otari, Mozilla.ai's open-source LLM gateway, or Stav's European inference gateway.

New Features

  • Use Agent('otari:anthropic:claude-sonnet-5-5') or build an OpenAIChatModel with OtariProvider(region='eu') or OtariProvider(base_url=...); region and base_url together raise a UserError.
  • Use Agent('stav:deepseek-ai/deepseek-v4-flash-0731') or build an OpenAIChatModel or OpenAIResponsesModel with StavProvider(region='eu'); the region is sent as the X-Stav-Runs-In header.
  • Both providers read their own *_API_KEY and *_BASE_URL environment variables, with no fallback to OPENAI_API_KEY.
  • Model names are sent unchanged; the provider prefix or creator/model id selects the family profile, and open-weight backends escape special tokens.
  • API-compatibility waivers cover the new otari and stav entries in OpenAIChatCompatibleProvider and OpenAIResponsesCompatibleProvider.