:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(llm-gateway): raise baseten token limits to the provider minimum (#106614)
Alessandro Pogliaghi74b8599a5458
diff --git a/services/llm-gateway/src/llm_gateway/baseten.py b/services/llm-gateway/src/llm_gateway/baseten.pyindex 7d4278da492e..72f2f45f8f14 100644--- a/services/llm-gateway/src/llm_gateway/baseten.py+++ b/services/llm-gateway/src/llm_gateway/baseten.py@@ -38,6 +38,8 @@ BASETEN_EXCLUSIVE_COST_MODELS: Final[dict[str, str]] = {BASETEN_GLM53_FLASH_PUBLIC_MODEL: BASETEN_GLM53_FLASH_METRIC_MODEL,}BASETEN_EXCLUSIVE_MODELS: frozenset[str] = frozenset(BASETEN_EXCLUSIVE_COST_MODELS)+BASETEN_MIN_MAX_TOKENS: Final = 2+BASETEN_MAX_TOKENS_PARAMS: Final = ("max_tokens", "max_completion_tokens", "max_output_tokens")def is_baseten_configured(settings: Settings) -> bool:@@ -63,6 +65,9 @@ def _inject_baseten_params(kwargs: dict[str, Any], api_base: str, api_key: str)kwargs["model"] = f"openai/{BASETEN_MODELS[model]}"kwargs.setdefault("drop_params", True)force_stream_usage(kwargs, continuous_usage_stats=True)+ for param in BASETEN_MAX_TOKENS_PARAMS:+ if isinstance(kwargs.get(param), int) and kwargs[param] < BASETEN_MIN_MAX_TOKENS:+ kwargs[param] = BASETEN_MIN_MAX_TOKENSdef make_baseten_anthropic_call(api_base: str, api_key: str) -> Callable[..., Awaitable[Any]]:diff --git a/services/llm-gateway/tests/test_baseten.py b/services/llm-gateway/tests/test_baseten.pyindex 5c8cdfb630fb..a3c9bf789a7c 100644--- a/services/llm-gateway/tests/test_baseten.py+++ b/services/llm-gateway/tests/test_baseten.py@@ -84,6 +84,23 @@ def test_inject_baseten_params_forces_streaming_usage() -> None:assert kwargs["stream_options"] == {"include_usage": True, "continuous_usage_stats": True}+ ("param", "requested", "sent"),+ [+ ("max_tokens", 1, 2),+ ("max_tokens", 4096, 4096),+ ("max_completion_tokens", 1, 2),+ ("max_output_tokens", 1, 2),+ ],+)+def test_inject_baseten_params_raises_token_limit_to_baseten_minimum(param: str, requested: int, sent: int) -> None:+ kwargs: dict[str, Any] = {"model": GLM_MODEL, param: requested}++ _inject_baseten_params(kwargs, "https://inference.baseten.co/v1", "test-key")++ assert kwargs[param] == sent++def test_ensure_baseten_configured_requires_api_key() -> None:with pytest.raises(HTTPException) as exc_info:ensure_baseten_configured(Settings())