Skip to main content

OpenAI-compatible LLM provider for exoclaw with streaming request bodies, per-model routing, and CPython + MicroPython support

Project description

exoclaw-provider-openai

Direct-httpx OpenAI-compatible provider for exoclaw.

Uses httpx directly (no OpenAI SDK, no LiteLLM) so the request body can be streamed as the JSON is built rather than materialized as one contiguous string before the POST. On long conversations this drops peak per-turn RAM from ≈3× prompt-size (list + JSON dump + httpx buffer) to ≈1× streaming buffer — see exoclaw/docs/memory-model.md Step B.

Shape

from exoclaw_provider_openai import Deployment, OpenAIStreamingProvider

provider = OpenAIStreamingProvider(
    default_model="zai/glm-4.7",
    deployments={
        "zai/glm-4.7":           Deployment(base_url="https://openrouter.ai/api/v1", api_key=OPENROUTER_KEY),
        "minimax/minimax-m2.7":  Deployment(base_url="https://openrouter.ai/api/v1", api_key=OPENROUTER_KEY),
        "openai/gpt-5.4":        Deployment(base_url="https://api.openai.com/v1",    api_key=OPENAI_KEY),
        "zai-direct/glm-5.1":    Deployment(base_url="https://api.z.ai/api/coding/paas/v4", api_key=ZAI_KEY),
    },
    fallbacks={
        "zai/glm-4.7":   ["minimax/minimax-m2.7"],
        "zai/glm-5.1":   ["minimax/minimax-m2.7"],
    },
)

Each model name maps to exactly one deployment (base URL + API key + optional extra headers). fallbacks is a per-model list — when the primary raises a retryable error (429, 5xx, timeout) the provider walks the fallback list until one succeeds or all are exhausted.

Routing policy

  • Each model → exactly one deployment. No load balancing across deployments for a single model.
  • Fallbacks are strict per-model lists. No automatic cross-provider fallback.
  • SSE response streaming is always on (the streaming-request-body path requires it as the codec; non-streaming responses aren't supported).
  • TTFT timeout: if the first response byte doesn't arrive inside stream_ttft_timeout seconds, the request is abandoned and the fallback list is tried. Default 15 s.

What's intentionally skipped vs. LiteLLM

  • Multi-provider cost tracking / usage normalization (OpenRouter returns the OpenAI shape directly; openclaw doesn't use cost tracking).
  • Automatic Anthropic cache_control tagging. If your deployment needs it, stamp it on the messages before handing them to chat() — this provider is OpenAI-schema only.
  • Deep parameter remapping across providers. Everything here is the OpenAI chat-completions schema; it's the caller's responsibility to send messages in that shape.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

exoclaw_provider_openai-0.4.0.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exoclaw_provider_openai-0.4.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file exoclaw_provider_openai-0.4.0.tar.gz.

File metadata

  • Download URL: exoclaw_provider_openai-0.4.0.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for exoclaw_provider_openai-0.4.0.tar.gz
Algorithm Hash digest
SHA256 796a5066ba658cbefd9757ff7c5332c2524342bfe9b964f89ea556b4df7de4af
MD5 e3a3b15ad4120804dcdfbc81456a953c
BLAKE2b-256 96d032d81983d19ff151f30d59249086b66729281a8419494c7edd5baa4d3a91

See more details on using hashes here.

File details

Details for the file exoclaw_provider_openai-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: exoclaw_provider_openai-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for exoclaw_provider_openai-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 256bfca3cd92caf3ff115e13400bc5cec370cfcf5a7a7ddcbf3ab4bd0f9a82c6
MD5 4cbeb083d942fb537b61d8d41f17dc43
BLAKE2b-256 ef6801d00b2f32d5d0e06d1000dc42e7f9e88b48ed4e393c24d35e7138d22d14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page