Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

docs+test(openai): replace payload_quirks docs; cover on_payload max_tokens

xf gong96df5aaf2f49
diff --git a/tests/providers/test_openai_capability.py b/tests/providers/test_openai_capability.py
index 90ef1b7..a8cbccd 100644
--- a/tests/providers/test_openai_capability.py
+++ b/tests/providers/test_openai_capability.py
@@ -261,3 +261,20 @@ async def test_reasoning_on_payload_and_level_both_applied():
p = OpenAIProvider(api_key="x", base_url="http://e", capability=cap)
payload = await _capture_payload_openai(p, _model(), thinking="medium")
assert payload["thinking"] == {"type": "enabled", "budget_tokens": 8192}
+
+
+async def test_max_tokens_field_renamed_preserves_on_payload_value():
+ """When on_payload sets max_tokens explicitly, the value survives the rename.
+ Mirrors test_temperature_free_preserves_caller_value_via_on_payload but for
+ max_tokens / max_completion_tokens."""
+ cap = CapabilityDescriptor(max_tokens_field="max_completion_tokens")
+ p = OpenAIProvider(api_key="x", base_url="http://e", capability=cap)
+
+ async def set_caller_max(kwargs, model):
+ kwargs["max_tokens"] = 1234
+ return kwargs
+
+ payload = await _capture_payload_openai(p, _model(), on_payload=set_caller_max)
+ assert payload["max_completion_tokens"] == 1234
+ assert "max_tokens" not in payload
diff --git a/website/docs/guides/providers/openai.md b/website/docs/guides/providers/openai.md
index a3eb08c..0bce388 100644
--- a/website/docs/guides/providers/openai.md
+++ b/website/docs/guides/providers/openai.md
@@ -27,7 +27,6 @@ provider = OpenAIProvider(
base_url=None, # set for OpenAI-compatible servers
extra_body=None, # merged into every request
extra_headers=None,
- payload_quirks=None, # ["max_completion_tokens_alias", …]
)
model = Model(
@@ -71,18 +70,15 @@ provider = OpenAIProvider(
If you need per-request mutation, use `on_payload` (see below).
-### `payload_quirks`
+### Capability descriptor
-Some servers require `max_tokens` instead of `max_completion_tokens`:
-
-```python
-provider = OpenAIProvider(
- api_key="…",
- payload_quirks=["max_completion_tokens_alias"],
-)
-```
-
-CubePi renames the key on the way out.
+Wire-shape differences between OpenAI and OpenAI-compatible backends
+(e.g. `max_tokens` vs `max_completion_tokens`, reasoning field names,
+temperature handling) are configured through a
+[`CapabilityDescriptor`](pathname:///pydoc/cubepi/providers/capability.html)
+passed at construction. For example, `max_tokens_field="max_completion_tokens"`
+renames the key on the way out. See the capability/preset catalog
+(cubepi `0.5+`) for the full set of knobs and ready-made model presets.
### Pointing at vLLM / LiteLLM / DeepSeek
@@ -166,8 +162,9 @@ provider.
- Set `include_usage=False` in `on_payload` (the field still goes
out, but is usually accepted as a no-op even by strict
backends).
- - Open an issue against cubepi to add a `payload_quirks` entry
- such as `"no_stream_options"` for native opt-out.
+ - Use the capability/preset catalog (cubepi `0.5+`) — register a
+ `CapabilityDescriptor` for your backend, or open an issue to add
+ one upstream.
- **Thinking events but no `thinking_*` events** — Your backend
surfaces reasoning under a non-standard field. Either add a fourth
branch via PR or transcode it with `on_payload`.