Skip to main content

keel-llm-adapter-openai

A reference keel-llm-protocol adapter for any OpenAI-compatible chat endpoint — OpenAI, Groq, OpenRouter, Mistral, Together, Fireworks, vLLM, Ollama (OpenAI mode), and more.

This package grounds the protocol standard in a working implementation. The status-code → error-taxonomy mapping, response/usage/finish-reason parsing, SSE streaming, and tool-call parsing here are real and tested against the actual OpenAI-compatible wire format — so keel-llm-protocol is proven against a real provider API, not asserted in the abstract.

Is this for you?

Adopt when — you're consuming via keel-llm-protocol / keel-llm-reliability and want one adapter that maps OpenAI / Groq / OpenRouter / Mistral / Together / Fireworks / vLLM / Ollama failures to the same typed taxonomy. Skip when — you're calling one provider directly in a simple app — the official openai SDK has a wider surface (batch, fine-tune, files, embeddings…); this adapter covers chat / streaming / tools.

Install

pip install keel-llm-adapter-openai     # pulls in keel-llm-protocol + httpx

Use

from keel_llm_adapter_openai import OpenAIAdapter
from keel_llm_protocol import user
from keel_llm_protocol.errors import RateLimitError, AdapterError

# Point base_url at any OpenAI-compatible endpoint:
adapter = OpenAIAdapter(
    model="llama-3.3-70b-versatile",
    api_key="...",
    base_url="https://api.groq.com/openai/v1",
    provider="groq",                       # -> model_key = "groq:llama-3.3-70b-versatile"
)

try:
    resp = await adapter.generate([user("Explain circuit breakers in one sentence.")])
    print(resp.text, resp.usage.total_tokens, resp.finish_reason)
except RateLimitError as e:
    ...                                    # healthy but throttled — back off; don't trip a breaker
except AdapterError as e:
    if e.retryable:
        ...                                # transient / timeout — retry or fail over

It implements all three capability protocols, so it type-checks anywhere any of them is required:

from keel_llm_protocol import ModelAdapter, StreamingModelAdapter, ToolCallingModelAdapter
assert isinstance(adapter, ModelAdapter)
assert isinstance(adapter, StreamingModelAdapter)
assert isinstance(adapter, ToolCallingModelAdapter)

Streaming

async for chunk in adapter.stream([user("Write a haiku.")]):
    print(chunk.delta, end="", flush=True)
    if chunk.usage:
        print(f"\n[{chunk.usage.total_tokens} tokens]")

Tools

from keel_llm_protocol import ToolSpec
weather = ToolSpec(name="get_weather", description="Get weather",
                   parameters={"type": "object", "properties": {"city": {"type": "string"}}})
resp = await adapter.generate_with_tools([user("Weather in SF?")], [weather])
for call in resp.tool_calls:
    print(call.name, call.arguments)      # YOU dispatch — the adapter only reports the request

Error mapping

Provider HTTP responses are mapped to the standard taxonomy so reliability logic is provider-agnostic:

Provider response Raised
429 (+ Retry-After) RateLimitError(retry_after=...) — retryable
401 / 403 AuthenticationError
400 + context_length_exceeded ContextLengthError
400 + content-filter ContentFilterError
400 (other) BadRequestError
5xx TransientError — retryable
timeout AdapterTimeoutError — retryable
connection error TransientError — retryable

A 200 response whose finish_reason is content_filter is returned (not raised) with finish_reason="content_filter".

Status

0.1.2 — 0.x while the API stabilizes through year one (breaking changes possible at minor bumps, documented in the CHANGELOG; pin exact versions).

The Keel toolkit

Composable, vendor-neutral LLM reliability libraries on PyPI: keel-llm-reliability · keel-llm-protocol · keel-llm-adapter-openai · keel-llm-adapter-anthropic · keel-llm-adapter-google · keel-circuit-breaker

MIT licensed.

Metadata

Release files for keel-llm-adapter-openai 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keel-llm-adapter-openai 0.1.2
File Size Uploaded Provenance
keel_llm_adapter_openai-0.1.2.tar.gz 9.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for keel-llm-adapter-openai 0.1.2
File Interpreter ABI Platform
keel_llm_adapter_openai-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.2 kB

Release files / keel_llm_adapter_openai-0.1.2.tar.gz

Download URL keel_llm_adapter_openai-0.1.2.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1dfc21846f20a6f54caee8fae5ff08153e420e3559854c1123a8d42662bdc637
BLAKE2b-256 checksum
How to use checksums
c44926f78343ae82ec9f943a4c444a6f94235571444624189ecb15f945b8dc69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 23, 2026.

Transparency log

Release files / keel_llm_adapter_openai-0.1.2-py3-none-any.whl

Download URL keel_llm_adapter_openai-0.1.2-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13644d1b541e27495a1a23cc38dc94974db8bff59322baf9c6b7ab23501f51eb
BLAKE2b-256 checksum
How to use checksums
85d916e64b28013d97f59735dbc8642dd9e283271b552112871bc3578ea55254
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 23, 2026.

Transparency log

Security for keel-llm-adapter-openai 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for keel_llm_adapter_openai-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page