Reference keel-llm-protocol adapter for any OpenAI-compatible chat endpoint (OpenAI, Groq, OpenRouter, Mistral, vLLM, Ollama, ...).
Project description
keel-llm-adapter-openai
A reference
keel-llm-protocoladapter 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.
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.0 — first release. Pin exact versions while in 0.x. Source: Keel monorepo.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keel_llm_adapter_openai-0.1.0.tar.gz.
File metadata
- Download URL: keel_llm_adapter_openai-0.1.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8af11f62d2582764fff02b97827562a7fff942f0dbb492c2ebc5b1c5203f4f35
|
|
| MD5 |
de1b2b87d94bc77f4b9172c2424fb795
|
|
| BLAKE2b-256 |
5da7f8469e4c6d929c8df928caeb09e75dcaf9e70fef5eb841c3c7f4a77607a0
|
Provenance
The following attestation bundles were made for keel_llm_adapter_openai-0.1.0.tar.gz:
Publisher:
publish-py.yml on keelplatform/keel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keel_llm_adapter_openai-0.1.0.tar.gz -
Subject digest:
8af11f62d2582764fff02b97827562a7fff942f0dbb492c2ebc5b1c5203f4f35 - Sigstore transparency entry: 1608456631
- Sigstore integration time:
-
Permalink:
keelplatform/keel@c39e5e08eeba3595ec85cad3340735c748be8b0e -
Branch / Tag:
refs/tags/py-llm-adapter-openai-v0.1.0 - Owner: https://github.com/keelplatform
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-py.yml@c39e5e08eeba3595ec85cad3340735c748be8b0e -
Trigger Event:
push
-
Statement type:
File details
Details for the file keel_llm_adapter_openai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: keel_llm_adapter_openai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81d6a4a34a61f6d748c2ddb33a8de82865d37046283950bb1fbe48354ca0f5d5
|
|
| MD5 |
8c7feb1dfe01bcdfd9d9cc94eb80d6c9
|
|
| BLAKE2b-256 |
e007ec538522d0002bd77c097c44dce0d6193d47b55cdfa3a0025d9315bd31e4
|
Provenance
The following attestation bundles were made for keel_llm_adapter_openai-0.1.0-py3-none-any.whl:
Publisher:
publish-py.yml on keelplatform/keel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keel_llm_adapter_openai-0.1.0-py3-none-any.whl -
Subject digest:
81d6a4a34a61f6d748c2ddb33a8de82865d37046283950bb1fbe48354ca0f5d5 - Sigstore transparency entry: 1608456743
- Sigstore integration time:
-
Permalink:
keelplatform/keel@c39e5e08eeba3595ec85cad3340735c748be8b0e -
Branch / Tag:
refs/tags/py-llm-adapter-openai-v0.1.0 - Owner: https://github.com/keelplatform
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-py.yml@c39e5e08eeba3595ec85cad3340735c748be8b0e -
Trigger Event:
push
-
Statement type: