From e30a3abf3aeba13a5a40b568f5678c884585edba Mon Sep 17 00:00:00 2001 From: Roshan Dam Date: Mon, 30 Mar 2026 14:37:43 +0000 Subject: [PATCH] fix(docs): add missing default values to OpenAPI spec Added explicit default values for parameters that have defined defaults in proxy implementation. Improves API clarity and DX. No runtime behavior changes. --- litellm/proxy/openapi.json | 18 +++-- .../proxy/test_openapi_schema_validation.py | 70 +++++++++++++++++++ 2 files changed, 82 insertions(+), 6 deletions(-) diff --git a/litellm/proxy/openapi.json b/litellm/proxy/openapi.json index 95517182667..355c060bf83 100644 --- a/litellm/proxy/openapi.json +++ b/litellm/proxy/openapi.json @@ -70,19 +70,23 @@ }, "temperature": { "type": "number", - "description": "The sampling temperature to be used" + "description": "The sampling temperature to be used", + "default": 1 }, "top_p": { "type": "number", - "description": "An alternative to sampling with temperature" + "description": "An alternative to sampling with temperature", + "default": 1 }, "n": { "type": "integer", - "description": "The number of chat completion choices to generate for each input message" + "description": "The number of chat completion choices to generate for each input message", + "default": 1 }, "stream": { "type": "boolean", - "description": "If set to true, it sends partial message deltas" + "description": "If set to true, it sends partial message deltas", + "default": false }, "stop": { "type": "array", @@ -97,11 +101,13 @@ }, "presence_penalty": { "type": "number", - "description": "It is used to penalize new tokens based on their existence in the text so far" + "description": "It is used to penalize new tokens based on their existence in the text so far", + "default": 0 }, "frequency_penalty": { "type": "number", - "description": "It is used to penalize new tokens based on their frequency in the text so far" + "description": "It is used to penalize new tokens based on their frequency in the text so far", + "default": 0 }, "logit_bias": { "type": "object", diff --git a/tests/test_litellm/proxy/test_openapi_schema_validation.py b/tests/test_litellm/proxy/test_openapi_schema_validation.py index aafe08f3033..37c62506e02 100644 --- a/tests/test_litellm/proxy/test_openapi_schema_validation.py +++ b/tests/test_litellm/proxy/test_openapi_schema_validation.py @@ -140,3 +140,73 @@ class TestCredentialEndpointsOpenAPISchema: assert "credential_name" in sig.parameters, ( "get_credential_by_name must have a credential_name parameter" ) + + +class TestOpenAPISpecDefaultValues: + """Test that the static openapi.json has correct default values for chat completion parameters.""" + + @pytest.fixture + def openapi_spec(self): + """Load the static openapi.json spec.""" + import json + from pathlib import Path + + spec_path = ( + Path(__file__).parents[3] / "litellm" / "proxy" / "openapi.json" + ) + with open(spec_path) as f: + return json.load(f) + + def test_temperature_has_default(self, openapi_spec): + """temperature should have default value 1.""" + props = ( + openapi_spec["paths"]["/chat/completions"]["post"]["requestBody"] + ["content"]["application/json"]["schema"]["properties"] + ) + assert "default" in props["temperature"] + assert props["temperature"]["default"] == 1 + + def test_top_p_has_default(self, openapi_spec): + """top_p should have default value 1.""" + props = ( + openapi_spec["paths"]["/chat/completions"]["post"]["requestBody"] + ["content"]["application/json"]["schema"]["properties"] + ) + assert "default" in props["top_p"] + assert props["top_p"]["default"] == 1 + + def test_n_has_default(self, openapi_spec): + """n should have default value 1.""" + props = ( + openapi_spec["paths"]["/chat/completions"]["post"]["requestBody"] + ["content"]["application/json"]["schema"]["properties"] + ) + assert "default" in props["n"] + assert props["n"]["default"] == 1 + + def test_stream_has_default(self, openapi_spec): + """stream should have default value false.""" + props = ( + openapi_spec["paths"]["/chat/completions"]["post"]["requestBody"] + ["content"]["application/json"]["schema"]["properties"] + ) + assert "default" in props["stream"] + assert props["stream"]["default"] is False + + def test_presence_penalty_has_default(self, openapi_spec): + """presence_penalty should have default value 0.""" + props = ( + openapi_spec["paths"]["/chat/completions"]["post"]["requestBody"] + ["content"]["application/json"]["schema"]["properties"] + ) + assert "default" in props["presence_penalty"] + assert props["presence_penalty"]["default"] == 0 + + def test_frequency_penalty_has_default(self, openapi_spec): + """frequency_penalty should have default value 0.""" + props = ( + openapi_spec["paths"]["/chat/completions"]["post"]["requestBody"] + ["content"]["application/json"]["schema"]["properties"] + ) + assert "default" in props["frequency_penalty"] + assert props["frequency_penalty"]["default"] == 0