Skip to content

Add bridge for /chat/completion -> /responses API #11632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 12, 2025

Conversation

krrishdholakia
Copy link
Contributor

@krrishdholakia krrishdholakia commented Jun 11, 2025

Title

Allow calling /responses API models via litellm.completion(..)

from litellm import completion
import os

os.environ["OPENAI_API_KEY"] = "sk-.."

response = litellm.completion(
    model="openai/codex-mini-latest",
    messages=[{"role": "user", "content": "Hey!"}],
)

Relevant issues

allow calling codex mini via chat completions (and other endpoints)

Builds on #11440 (s/o @matthid)
Closes #9754
Closes #10925

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test

Changes

…arate folder

future work to support completion_to_responses bridge

allow calling codex mini via chat completions (and other endpoints)
Copy link

vercel bot commented Jun 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 4:56am

@krrishdholakia krrishdholakia changed the title refactor(responses/): refactor to move responses_to_completion in sep… Add bridge for /chat/completion -> /responses API Jun 11, 2025
write it like a custom llm - requires lesser 'new' components
…ses bridge

Allows calling codex mini via proxy
maintain <50 LOC
@krrishdholakia krrishdholakia merged commit 7f2e188 into main Jun 12, 2025
37 of 46 checks passed
@matthid
Copy link
Contributor

matthid commented Jun 12, 2025

@krrishdholakia Thanks for taking this further! However, it seems something broke in the refactoring: The API Key is no longer used from the configuration but none is sent...

{
  "error": {
    "message": "Incorrect API key provided: None. You can find your API key at https://platform.openai.com/account/api-keys.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}

(from the logs)

and litellm will respond with:

{
	"error": {
		"message": "litellm.AuthenticationError: AuthenticationError: OpenAIException - {\n  \"error\": {\n    \"message\": \"Incorrect API key provided: None. You can find your API key at https://platform.openai.com/account/api-keys.\",\n    \"type\": \"invalid_request_error\",\n    \"param\": null,\n    \"code\": \"invalid_api_key\"\n  }\n}. Received Model Group=openai/codex-mini-latest\nAvailable Model Group Fallbacks=None",
		"type": null,
		"param": null,
		"code": "401"
	}
}

@matthid
Copy link
Contributor

matthid commented Jun 12, 2025

#11668 This fix worked for me.

@krrishdholakia
Copy link
Contributor Author

Hi @matthid can you share steps to repro your error?

@matthid
Copy link
Contributor

matthid commented Jun 12, 2025

I sent a completion message to codex-mini-latest with the following proxy config:

  - model_name: "openai/*"
    litellm_params:
      model: "openai/*"
      api_key: "...."
      drop_params: true

Nothing special otherwise.

@krrishdholakia krrishdholakia deleted the litellm_responses_api_bridge branch June 13, 2025 00:26
@krrishdholakia
Copy link
Contributor Author

@matthid fixed on main 👍

@matthid
Copy link
Contributor

matthid commented Jun 13, 2025

@krrishdholakia Further testing revealed that the responses API is a bit more picky about the types: d2db195

Also your fix doesn't work for me since it now complains with:

400: litellm.BadRequestError: OpenAIException - {
"error": {
"message": "Invalid 'metadata': too many properties. Expected an object with at most 16 properties, but got an object with 29 properties instead.",
"type": "invalid_request_error",
"param": "metadata",
"code": "object_above_max_properties"
}
}. Received Model Group=openai/codex-mini-latest
Available Model Group Fallbacks=None

I actually run into the same and settled into only setting the two properties by hand (not knowing better)

@krrishdholakia
Copy link
Contributor Author

How are you testing this? @matthid

(appreciate your help qa'ing this)

@matthid
Copy link
Contributor

matthid commented Jun 13, 2025

@krrishdholakia Sure, I'm happy that a basic version is in main ;)

Same as before via the same proxy config: The types error happens when you there is an agent message in the chat completion (I use openwebui to test this, so this happens as soon as you continue an existing chat):

400: litellm.BadRequestError: OpenAIException - {
"error": {
"message": "Invalid value: 'input_text'. Supported values are: 'output_text' and 'refusal'.",
"type": "invalid_request_error",
"param": "input[1].content[0]",
"code": "invalid_value"
}
}. Received Model Group=openai/codex-mini-latest
Available Model Group Fallbacks=None

The Invalid 'metadata': too many properties Error happened to me also when I used

result = await aresponses(
            **litellm_params,
            **request_data,
            aresponses=True
        )

hence why I used

        result = await aresponses(
            **request_data,
            aresponses=True,
            api_base=litellm_params["api_base"],
            api_key=litellm_params["api_key"],
        )

I'm not sure why we sending all of the stuff to openai, apparently only 16 fields are allowed.

@krrishdholakia
Copy link
Contributor Author

Thanks @matthid - i'll try to connect to OpenWebUI and test as well

@krrishdholakia
Copy link
Contributor Author

can i see your full config? curious if there's any other settings i should be adding

@matthid
Copy link
Contributor

matthid commented Jun 14, 2025

Well the full setup is also quite easy:

Logs from local dev env (WSL2)

Request (http://172.27.231.219:4000/chat/completions):

{
	"model": "openai/codex-mini-latest",
	"stream": false,
	"messages": [
		{
			"role": "user",
			"content": "What are some things to think about?"
		}
	]
}

Logs:

import sys; print('Python %s on %s' % (sys.version, sys.platform))
/home/matthid/proj/litellm/.venv/bin/python -X pycache_prefix=/home/matthid/.cache/JetBrains/PyCharm2025.1/cpython-cache /home/matthid/.cache/JetBrains/RemoteDev/dist/321c40d7bee68_pycharm-2025.1.1.1/plugins/python-ce/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 34931 --file /home/matthid/proj/litellm/litellm/proxy/proxy_cli.py --config /home/matthid/litellm_config.yaml 
Connected to pydev debugger (build 251.25410.159)
INFO:     Started server process [903961]
INFO:     Waiting for application startup.
04:54:52 - LiteLLM Proxy:DEBUG: proxy_server.py:521 - litellm.proxy.proxy_server.py::startup() - CHECKING PREMIUM USER - False
04:54:52 - LiteLLM Proxy:DEBUG: litellm_license.py:102 - litellm.proxy.auth.litellm_license.py::is_premium() - ENTERING 'IS_PREMIUM' - LiteLLM License=None
04:54:52 - LiteLLM Proxy:DEBUG: litellm_license.py:111 - litellm.proxy.auth.litellm_license.py::is_premium() - Updated 'self.license_str' - None
04:54:52 - LiteLLM Proxy:DEBUG: proxy_server.py:534 - worker_config: {"model": null, "alias": null, "api_base": null, "api_version": "2024-07-01-preview", "debug": false, "detailed_debug": false, "temperature": null, "max_tokens": null, "request_timeout": null, "max_budget": null, "telemetry": true, "drop_params": false, "add_function_to_prompt": false, "headers": null, "save": false, "config": "/home/matthid/litellm_config.yaml", "use_queue": false}
04:54:52 - LiteLLM Proxy:DEBUG: proxy_server.py:1850 -  setting litellm.check_provider_endpoint=True
#------------------------------------------------------------#
#                                                            #
#         'The worst thing about this product is...'          #
#        https://github.com/BerriAI/litellm/issues/new        #
#                                                            #
#------------------------------------------------------------#
 Thank you for using LiteLLM! - Krrish & Ishaan
Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM: Proxy initialized with Config, Set models:
    anthropic/*
    ollama/*
    openai/*
    google-gemini/*
04:54:52 - LiteLLM Proxy:DEBUG: proxy_server.py:2126 - _alerting_callbacks: {'user_header_name': 'X-OpenWebUI-User-Email'}
04:54:56 - LiteLLM Router:DEBUG: router.py:4631 - 
Initialized Model List ['anthropic/*', 'ollama/*', 'openai/*', 'google-gemini/*']
04:54:56 - LiteLLM Router:INFO: router.py:660 - Routing strategy: simple-shuffle
04:54:56 - LiteLLM Router:DEBUG: router.py:545 - Intialized router with Routing strategy: simple-shuffle
Routing enable_pre_call_checks: False
Routing fallbacks: None
Routing content fallbacks: None
Routing context window fallbacks: None
Router Redis Caching=None
04:54:56 - LiteLLM Proxy:DEBUG: proxy_server.py:608 - prisma_client: None
04:54:56 - LiteLLM Proxy:DEBUG: hanging_request_check.py:148 - Checking for hanging requests....
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:4000 (Press CTRL+C to quit)
04:55:03 - LiteLLM Proxy:DEBUG: common_request_processing.py:351 - Request received by LiteLLM:
{
    "model": "openai/codex-mini-latest",
    "stream": false,
    "messages": [
        {
            "role": "user",
            "content": "What are some things to think about?"
        }
    ]
}
04:55:03 - LiteLLM Proxy:DEBUG: litellm_pre_call_utils.py:565 - Request Headers: Headers({'host': '172.27.231.219:4000', 'content-type': 'application/json', 'authorization': 'Bearer master_key', 'accept': '*/*', 'content-length': '157'})
04:55:03 - LiteLLM Proxy:DEBUG: litellm_pre_call_utils.py:571 - receiving data: {'model': 'openai/codex-mini-latest', 'stream': False, 'messages': [{'role': 'user', 'content': 'What are some things to think about?'}], 'proxy_server_request': {'url': 'http://172.27.231.219:4000/chat/completions', 'method': 'POST', 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'body': {'model': 'openai/codex-mini-latest', 'stream': False, 'messages': [{'role': 'user', 'content': 'What are some things to think about?'}]}}}
04:55:03 - LiteLLM Proxy:DEBUG: litellm_pre_call_utils.py:737 - [PROXY] returned data from litellm_pre_call_utils: {'model': 'openai/codex-mini-latest', 'stream': False, 'messages': [{'role': 'user', 'content': 'What are some things to think about?'}], 'proxy_server_request': {'url': 'http://172.27.231.219:4000/chat/completions', 'method': 'POST', 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'body': {'model': 'openai/codex-mini-latest', 'stream': False, 'messages': [{'role': 'user', 'content': 'What are some things to think about?'}]}}, 'metadata': {'requester_metadata': {}, 'user_api_key_hash': 'user_api_key', 'user_api_key_alias': None, 'user_api_key_team_id': None, 'user_api_key_user_id': None, 'user_api_key_org_id': None, 'user_api_key_team_alias': None, 'user_api_key_end_user_id': None, 'user_api_key_user_email': None, 'user_api_key': 'user_api_key', 'user_api_end_user_max_budget': None, 'litellm_api_version': '1.72.6', 'global_max_parallel_requests': None, 'user_api_key_team_max_budget': None, 'user_api_key_team_spend': None, 'user_api_key_spend': 0.0, 'user_api_key_max_budget': None, 'user_api_key_model_max_budget': {}, 'user_api_key_metadata': {}, 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'endpoint': 'http://172.27.231.219:4000/chat/completions', 'litellm_parent_otel_span': None, 'requester_ip_address': ''}}
04:55:03 - LiteLLM Proxy:DEBUG: utils.py:541 - Inside Proxy Logging Pre-call hook!
04:55:03 - LiteLLM Proxy:DEBUG: max_budget_limiter.py:23 - Inside Max Budget Limiter Pre-Call Hook
04:55:03 - LiteLLM Proxy:DEBUG: parallel_request_limiter.py:48 - Inside Max Parallel Request Pre-Call Hook
04:55:03 - LiteLLM Proxy:INFO: parallel_request_limiter.py:68 - Current Usage of key in this minute: None
04:55:03 - LiteLLM Proxy:DEBUG: cache_control_check.py:27 - Inside Cache Control Check Pre-Call Hook
04:55:03 - LiteLLM Router:DEBUG: router.py:3605 - Inside async function with retries.
04:55:03 - LiteLLM Router:DEBUG: router.py:3625 - async function w/ retries: original_function - <bound method Router._acompletion of <litellm.router.Router object at 0x7dd53f005690>>, num_retries - 2
04:55:03 - LiteLLM Router:DEBUG: router.py:1013 - Inside _acompletion()- model: openai/codex-mini-latest; kwargs: {'proxy_server_request': {'url': 'http://172.27.231.219:4000/chat/completions', 'method': 'POST', 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'body': {'model': 'openai/codex-mini-latest', 'stream': False, 'messages': [{'role': 'user', 'content': 'What are some things to think about?'}]}}, 'metadata': {'requester_metadata': {}, 'user_api_key_hash': 'user_api_key', 'user_api_key_alias': None, 'user_api_key_team_id': None, 'user_api_key_user_id': None, 'user_api_key_org_id': None, 'user_api_key_team_alias': None, 'user_api_key_end_user_id': None, 'user_api_key_user_email': None, 'user_api_key': 'user_api_key', 'user_api_end_user_max_budget': None, 'litellm_api_version': '1.72.6', 'global_max_parallel_requests': None, 'user_api_key_team_max_budget': None, 'user_api_key_team_spend': None, 'user_api_key_spend': 0.0, 'user_api_key_max_budget': None, 'user_api_key_model_max_budget': {}, 'user_api_key_metadata': {}, 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'endpoint': 'http://172.27.231.219:4000/chat/completions', 'litellm_parent_otel_span': None, 'requester_ip_address': '', 'model_group': 'openai/codex-mini-latest', 'model_group_size': 1}, 'litellm_call_id': '0600e8c8-957d-4e73-993a-b493567fb61c', 'litellm_logging_obj': <litellm.litellm_core_utils.litellm_logging.Logging object at 0x7dd53cf9c130>, 'stream': False, 'litellm_trace_id': '2140f3a3-db2d-43b0-8e8a-127c9da85cec'}
04:55:03 - LiteLLM Router:DEBUG: cooldown_handlers.py:326 - retrieve cooldown models: []
04:55:03 - LiteLLM Router:DEBUG: router.py:6161 - async cooldown deployments: []
04:55:03 - LiteLLM Router:DEBUG: router.py:6164 - cooldown_deployments: []
04:55:03 - LiteLLM Router:DEBUG: router.py:6484 - cooldown deployments: []
04:55:04 - LiteLLM Router:DEBUG: router.py:4077 - Router: Entering 'deployment_callback_on_failure'
04:55:04 - LiteLLM Router:DEBUG: cooldown_handlers.py:260 - checks 'should_run_cooldown_logic'
04:55:04 - LiteLLM Router:DEBUG: cooldown_handlers.py:136 - Should Not Run Cooldown Logic: _is_cooldown_required returned False
04:55:04 - LiteLLM Router:DEBUG: cooldown_handlers.py:269 - should_run_cooldown_logic returned False
04:55:04 - LiteLLM Proxy:DEBUG: parallel_request_limiter.py:48 - Inside Max Parallel Request Failure Hook
04:55:04 - LiteLLM Proxy:DEBUG: parallel_request_limiter.py:48 - user_api_key: user_api_key
04:55:04 - LiteLLM Proxy:DEBUG: parallel_request_limiter.py:48 - updated_value in failure call: {'current_requests': 0, 'current_tpm': 0, 'current_rpm': 1}
04:55:04 - LiteLLM Router:INFO: router.py:1131 - litellm.acompletion(model=openai/codex-mini-latest) Exception litellm.BadRequestError: OpenAIException - {
  "error": {
    "message": "Invalid 'metadata': too many properties. Expected an object with at most 16 properties, but got an object with 29 properties instead.",
    "type": "invalid_request_error",
    "param": "metadata",
    "code": "object_above_max_properties"
  }
}
04:55:04 - LiteLLM Router:DEBUG: cooldown_handlers.py:326 - retrieve cooldown models: []
04:55:04 - LiteLLM Router:INFO: router.py:3684 - Retrying request with num_retries: 2
04:55:04 - LiteLLM Router:DEBUG: router.py:1013 - Inside _acompletion()- model: openai/codex-mini-latest; kwargs: {'proxy_server_request': {'url': 'http://172.27.231.219:4000/chat/completions', 'method': 'POST', 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'body': {'model': 'openai/codex-mini-latest', 'stream': False, 'messages': [{'role': 'user', 'content': 'What are some things to think about?'}]}}, 'metadata': {'requester_metadata': {}, 'user_api_key_hash': 'user_api_key', 'user_api_key_alias': None, 'user_api_key_team_id': None, 'user_api_key_user_id': None, 'user_api_key_org_id': None, 'user_api_key_team_alias': None, 'user_api_key_end_user_id': None, 'user_api_key_user_email': None, 'user_api_key': 'user_api_key', 'user_api_end_user_max_budget': None, 'litellm_api_version': '1.72.6', 'global_max_parallel_requests': None, 'user_api_key_team_max_budget': None, 'user_api_key_team_spend': None, 'user_api_key_spend': 0.0, 'user_api_key_max_budget': None, 'user_api_key_model_max_budget': {}, 'user_api_key_metadata': {}, 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'endpoint': 'http://172.27.231.219:4000/chat/completions', 'litellm_parent_otel_span': None, 'requester_ip_address': '', 'model_group': 'openai/codex-mini-latest', 'model_group_size': 1, 'deployment': 'openai/codex-mini-latest', 'model_info': {'id': 'c9d1febe3f1fe18c1ba6b9d273cd9ba6af856f5a5ebc4113f6be5a9b73eff00b', 'db_model': False}, 'api_base': None, 'caching_groups': None, 'previous_models': [{'exception_type': 'BadRequestError', 'exception_string': 'litellm.BadRequestError: OpenAIException - {\n  "error": {\n    "message": "Invalid \'metadata\': too many properties. Expected an object with at most 16 properties, but got an object with 29 properties instead.",\n    "type": "invalid_request_error",\n    "param": "metadata",\n    "code": "object_above_max_properties"\n  }\n}', 'proxy_server_request': {'url': 'http://172.27.231.219:4000/chat/completions', 'method': 'POST', 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'body': {'model': 'openai/codex-mini-latest', 'stream': False, 'messages': [{'role': 'user', 'content': 'What are some things to think about?'}]}}, 'metadata': {'requester_metadata': {}, 'user_api_key_hash': 'user_api_key', 'user_api_key_alias': None, 'user_api_key_team_id': None, 'user_api_key_user_id': None, 'user_api_key_org_id': None, 'user_api_key_team_alias': None, 'user_api_key_end_user_id': None, 'user_api_key_user_email': None, 'user_api_key': 'user_api_key', 'user_api_end_user_max_budget': None, 'litellm_api_version': '1.72.6', 'global_max_parallel_requests': None, 'user_api_key_team_max_budget': None, 'user_api_key_team_spend': None, 'user_api_key_spend': 0.0, 'user_api_key_max_budget': None, 'user_api_key_model_max_budget': {}, 'user_api_key_metadata': {}, 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'endpoint': 'http://172.27.231.219:4000/chat/completions', 'litellm_parent_otel_span': None, 'requester_ip_address': '', 'model_group': 'openai/codex-mini-latest', 'model_group_size': 1, 'deployment': 'openai/codex-mini-latest', 'model_info': {'id': 'c9d1febe3f1fe18c1ba6b9d273cd9ba6af856f5a5ebc4113f6be5a9b73eff00b', 'db_model': False}, 'api_base': None, 'caching_groups': None}, 'litellm_call_id': '0600e8c8-957d-4e73-993a-b493567fb61c', 'litellm_logging_obj': <litellm.litellm_core_utils.litellm_logging.Logging object at 0x7dd53cf9c130>, 'model': 'openai/codex-mini-latest', 'stream': False, 'litellm_trace_id': '2140f3a3-db2d-43b0-8e8a-127c9da85cec'}]}, 'litellm_call_id': '0600e8c8-957d-4e73-993a-b493567fb61c', 'litellm_logging_obj': <litellm.litellm_core_utils.litellm_logging.Logging object at 0x7dd53cf9c130>, 'stream': False, 'litellm_trace_id': '2140f3a3-db2d-43b0-8e8a-127c9da85cec'}
04:55:04 - LiteLLM Router:DEBUG: cooldown_handlers.py:326 - retrieve cooldown models: []
04:55:04 - LiteLLM Router:DEBUG: router.py:6161 - async cooldown deployments: []
04:55:04 - LiteLLM Router:DEBUG: router.py:6164 - cooldown_deployments: []
04:55:04 - LiteLLM Router:DEBUG: router.py:6484 - cooldown deployments: []
04:55:04 - LiteLLM Router:INFO: router.py:1131 - litellm.acompletion(model=openai/codex-mini-latest) Exception litellm.InternalServerError: InternalServerError: OpenAIException - Object of type Logging is not JSON serializable
04:55:04 - LiteLLM Router:DEBUG: cooldown_handlers.py:326 - retrieve cooldown models: []
04:55:04 - LiteLLM Router:DEBUG: router.py:1013 - Inside _acompletion()- model: openai/codex-mini-latest; kwargs: {'proxy_server_request': {'url': 'http://172.27.231.219:4000/chat/completions', 'method': 'POST', 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'body': {'model': 'openai/codex-mini-latest', 'stream': False, 'messages': [{'role': 'user', 'content': 'What are some things to think about?'}]}}, 'metadata': {'requester_metadata': {}, 'user_api_key_hash': 'user_api_key', 'user_api_key_alias': None, 'user_api_key_team_id': None, 'user_api_key_user_id': None, 'user_api_key_org_id': None, 'user_api_key_team_alias': None, 'user_api_key_end_user_id': None, 'user_api_key_user_email': None, 'user_api_key': 'user_api_key', 'user_api_end_user_max_budget': None, 'litellm_api_version': '1.72.6', 'global_max_parallel_requests': None, 'user_api_key_team_max_budget': None, 'user_api_key_team_spend': None, 'user_api_key_spend': 0.0, 'user_api_key_max_budget': None, 'user_api_key_model_max_budget': {}, 'user_api_key_metadata': {}, 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'endpoint': 'http://172.27.231.219:4000/chat/completions', 'litellm_parent_otel_span': None, 'requester_ip_address': '', 'model_group': 'openai/codex-mini-latest', 'model_group_size': 1, 'deployment': 'openai/codex-mini-latest', 'model_info': {'id': 'c9d1febe3f1fe18c1ba6b9d273cd9ba6af856f5a5ebc4113f6be5a9b73eff00b', 'db_model': False}, 'api_base': None, 'caching_groups': None, 'previous_models': [{'exception_type': 'BadRequestError', 'exception_string': 'litellm.BadRequestError: OpenAIException - {\n  "error": {\n    "message": "Invalid \'metadata\': too many properties. Expected an object with at most 16 properties, but got an object with 29 properties instead.",\n    "type": "invalid_request_error",\n    "param": "metadata",\n    "code": "object_above_max_properties"\n  }\n}', 'proxy_server_request': {'url': 'http://172.27.231.219:4000/chat/completions', 'method': 'POST', 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'body': {'model': 'openai/codex-mini-latest', 'stream': False, 'messages': [{'role': 'user', 'content': 'What are some things to think about?'}]}}, 'metadata': {'requester_metadata': {}, 'user_api_key_hash': 'user_api_key', 'user_api_key_alias': None, 'user_api_key_team_id': None, 'user_api_key_user_id': None, 'user_api_key_org_id': None, 'user_api_key_team_alias': None, 'user_api_key_end_user_id': None, 'user_api_key_user_email': None, 'user_api_key': 'user_api_key', 'user_api_end_user_max_budget': None, 'litellm_api_version': '1.72.6', 'global_max_parallel_requests': None, 'user_api_key_team_max_budget': None, 'user_api_key_team_spend': None, 'user_api_key_spend': 0.0, 'user_api_key_max_budget': None, 'user_api_key_model_max_budget': {}, 'user_api_key_metadata': {}, 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'endpoint': 'http://172.27.231.219:4000/chat/completions', 'litellm_parent_otel_span': None, 'requester_ip_address': '', 'model_group': 'openai/codex-mini-latest', 'model_group_size': 1, 'deployment': 'openai/codex-mini-latest', 'model_info': {'id': 'c9d1febe3f1fe18c1ba6b9d273cd9ba6af856f5a5ebc4113f6be5a9b73eff00b', 'db_model': False}, 'api_base': None, 'caching_groups': None}, 'litellm_call_id': '0600e8c8-957d-4e73-993a-b493567fb61c', 'litellm_logging_obj': <litellm.litellm_core_utils.litellm_logging.Logging object at 0x7dd53cf9c130>, 'model': 'openai/codex-mini-latest', 'stream': False, 'litellm_trace_id': '2140f3a3-db2d-43b0-8e8a-127c9da85cec'}, {'exception_type': 'InternalServerError', 'exception_string': 'litellm.InternalServerError: InternalServerError: OpenAIException - Object of type Logging is not JSON serializable', 'proxy_server_request': {'url': 'http://172.27.231.219:4000/chat/completions', 'method': 'POST', 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'body': {'model': 'openai/codex-mini-latest', 'stream': False, 'messages': [{'role': 'user', 'content': 'What are some things to think about?'}]}}, 'metadata': {'requester_metadata': {}, 'user_api_key_hash': 'user_api_key', 'user_api_key_alias': None, 'user_api_key_team_id': None, 'user_api_key_user_id': None, 'user_api_key_org_id': None, 'user_api_key_team_alias': None, 'user_api_key_end_user_id': None, 'user_api_key_user_email': None, 'user_api_key': 'user_api_key', 'user_api_end_user_max_budget': None, 'litellm_api_version': '1.72.6', 'global_max_parallel_requests': None, 'user_api_key_team_max_budget': None, 'user_api_key_team_spend': None, 'user_api_key_spend': 0.0, 'user_api_key_max_budget': None, 'user_api_key_model_max_budget': {}, 'user_api_key_metadata': {}, 'headers': {'host': '172.27.231.219:4000', 'content-type': 'application/json', 'accept': '*/*', 'content-length': '157'}, 'endpoint': 'http://172.27.231.219:4000/chat/completions', 'litellm_parent_otel_span': None, 'requester_ip_address': '', 'model_group': 'openai/codex-mini-latest', 'model_group_size': 1, 'deployment': 'openai/codex-mini-latest', 'model_info': {'id': 'c9d1febe3f1fe18c1ba6b9d273cd9ba6af856f5a5ebc4113f6be5a9b73eff00b', 'db_model': False}, 'api_base': None, 'caching_groups': None}, 'litellm_call_id': '0600e8c8-957d-4e73-993a-b493567fb61c', 'litellm_logging_obj': <litellm.litellm_core_utils.litellm_logging.Logging object at 0x7dd53cf9c130>, 'model': 'openai/codex-mini-latest', 'stream': False, 'litellm_trace_id': '2140f3a3-db2d-43b0-8e8a-127c9da85cec'}]}, 'litellm_call_id': '0600e8c8-957d-4e73-993a-b493567fb61c', 'litellm_logging_obj': <litellm.litellm_core_utils.litellm_logging.Logging object at 0x7dd53cf9c130>, 'stream': False, 'litellm_trace_id': '2140f3a3-db2d-43b0-8e8a-127c9da85cec'}
04:55:04 - LiteLLM Router:DEBUG: cooldown_handlers.py:326 - retrieve cooldown models: []
04:55:04 - LiteLLM Router:DEBUG: router.py:6161 - async cooldown deployments: []
04:55:04 - LiteLLM Router:DEBUG: router.py:6164 - cooldown_deployments: []
04:55:04 - LiteLLM Router:DEBUG: router.py:6484 - cooldown deployments: []
04:55:04 - LiteLLM Router:INFO: router.py:1131 - litellm.acompletion(model=openai/codex-mini-latest) Exception litellm.InternalServerError: InternalServerError: OpenAIException - Object of type Logging is not JSON serializable
04:55:04 - LiteLLM Router:DEBUG: cooldown_handlers.py:326 - retrieve cooldown models: []
04:55:05 - LiteLLM Router:DEBUG: router.py:3372 - TracebackTraceback (most recent call last):
  File "/home/matthid/proj/litellm/litellm/llms/custom_httpx/llm_http_handler.py", line 1635, in async_response_api_handler
    response = await async_httpx_client.post(
  File "/home/matthid/proj/litellm/litellm/litellm_core_utils/logging_utils.py", line 135, in async_wrapper
    result = await func(*args, **kwargs)
  File "/home/matthid/proj/litellm/litellm/llms/custom_httpx/http_handler.py", line 278, in post
    raise e
  File "/home/matthid/proj/litellm/litellm/llms/custom_httpx/http_handler.py", line 234, in post
    response.raise_for_status()
  File "/home/matthid/proj/litellm/.venv/lib/python3.10/site-packages/httpx/_models.py", line 829, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://api.openai.com/v1/responses'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/matthid/proj/litellm/litellm/responses/main.py", line 171, in aresponses
    response = await init_response
  File "/home/matthid/proj/litellm/litellm/llms/custom_httpx/llm_http_handler.py", line 1644, in async_response_api_handler
    raise self._handle_error(
  File "/home/matthid/proj/litellm/litellm/llms/custom_httpx/llm_http_handler.py", line 2371, in _handle_error
    raise provider_config.get_error_class(
  File "/home/matthid/proj/litellm/litellm/llms/base_llm/responses/transformation.py", line 203, in get_error_class
    raise BaseLLMException(
litellm.llms.base_llm.chat.transformation.BaseLLMException: {
  "error": {
    "message": "Invalid 'metadata': too many properties. Expected an object with at most 16 properties, but got an object with 29 properties instead.",
    "type": "invalid_request_error",
    "param": "metadata",
    "code": "object_above_max_properties"
  }
}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/matthid/proj/litellm/litellm/router.py", line 3364, in async_function_with_fallbacks
    response = await self.async_function_with_retries(*args, **kwargs)
  File "/home/matthid/proj/litellm/litellm/router.py", line 3742, in async_function_with_retries
    raise original_exception
  File "/home/matthid/proj/litellm/litellm/router.py", line 3633, in async_function_with_retries
    response = await self.make_call(original_function, *args, **kwargs)
  File "/home/matthid/proj/litellm/litellm/router.py", line 3751, in make_call
    response = await response
  File "/home/matthid/proj/litellm/litellm/router.py", line 1136, in _acompletion
    raise e
  File "/home/matthid/proj/litellm/litellm/router.py", line 1095, in _acompletion
    response = await _response
  File "/home/matthid/proj/litellm/litellm/utils.py", line 1494, in wrapper_async
    raise e
  File "/home/matthid/proj/litellm/litellm/utils.py", line 1355, in wrapper_async
    result = await original_function(*args, **kwargs)
  File "/home/matthid/proj/litellm/litellm/main.py", line 544, in acompletion
    raise exception_type(
  File "/home/matthid/proj/litellm/litellm/main.py", line 525, in acompletion
    response = await init_response
  File "/home/matthid/proj/litellm/litellm/completion_extras/litellm_responses_transformation/handler.py", line 166, in acompletion
    result = await aresponses(
  File "/home/matthid/proj/litellm/litellm/utils.py", line 1494, in wrapper_async
    raise e
  File "/home/matthid/proj/litellm/litellm/utils.py", line 1355, in wrapper_async
    result = await original_function(*args, **kwargs)
  File "/home/matthid/proj/litellm/litellm/responses/main.py", line 184, in aresponses
    raise litellm.exception_type(
  File "/home/matthid/proj/litellm/litellm/litellm_core_utils/exception_mapping_utils.py", line 2271, in exception_type
    raise e
  File "/home/matthid/proj/litellm/litellm/litellm_core_utils/exception_mapping_utils.py", line 369, in exception_type
    raise BadRequestError(
litellm.exceptions.BadRequestError: litellm.BadRequestError: OpenAIException - {
  "error": {
    "message": "Invalid 'metadata': too many properties. Expected an object with at most 16 properties, but got an object with 29 properties instead.",
    "type": "invalid_request_error",
    "param": "metadata",
    "code": "object_above_max_properties"
  }
} LiteLLM Retried: 1 times, LiteLLM Max Retries: 2
04:55:05 - LiteLLM Router:INFO: router.py:3393 - Trying to fallback b/w models
04:55:05 - LiteLLM Proxy:ERROR: common_request_processing.py:487 - litellm.proxy.proxy_server._handle_llm_api_exception(): Exception occured - litellm.BadRequestError: OpenAIException - {
  "error": {
    "message": "Invalid 'metadata': too many properties. Expected an object with at most 16 properties, but got an object with 29 properties instead.",
    "type": "invalid_request_error",
    "param": "metadata",
    "code": "object_above_max_properties"
  }
}. Received Model Group=openai/codex-mini-latest
Available Model Group Fallbacks=None LiteLLM Retried: 1 times, LiteLLM Max Retries: 2
Traceback (most recent call last):
  File "/home/matthid/proj/litellm/litellm/llms/custom_httpx/llm_http_handler.py", line 1635, in async_response_api_handler
    response = await async_httpx_client.post(
  File "/home/matthid/proj/litellm/litellm/litellm_core_utils/logging_utils.py", line 135, in async_wrapper
    result = await func(*args, **kwargs)
  File "/home/matthid/proj/litellm/litellm/llms/custom_httpx/http_handler.py", line 278, in post
    raise e
  File "/home/matthid/proj/litellm/litellm/llms/custom_httpx/http_handler.py", line 234, in post
    response.raise_for_status()
  File "/home/matthid/proj/litellm/.venv/lib/python3.10/site-packages/httpx/_models.py", line 829, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://api.openai.com/v1/responses'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/matthid/proj/litellm/litellm/responses/main.py", line 171, in aresponses
    response = await init_response
  File "/home/matthid/proj/litellm/litellm/llms/custom_httpx/llm_http_handler.py", line 1644, in async_response_api_handler
    raise self._handle_error(
  File "/home/matthid/proj/litellm/litellm/llms/custom_httpx/llm_http_handler.py", line 2371, in _handle_error
    raise provider_config.get_error_class(
  File "/home/matthid/proj/litellm/litellm/llms/base_llm/responses/transformation.py", line 203, in get_error_class
    raise BaseLLMException(
litellm.llms.base_llm.chat.transformation.BaseLLMException: {
  "error": {
    "message": "Invalid 'metadata': too many properties. Expected an object with at most 16 properties, but got an object with 29 properties instead.",
    "type": "invalid_request_error",
    "param": "metadata",
    "code": "object_above_max_properties"
  }
}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/matthid/proj/litellm/litellm/proxy/proxy_server.py", line 3626, in chat_completion
    return await base_llm_response_processor.base_process_llm_request(
  File "/home/matthid/proj/litellm/litellm/proxy/common_request_processing.py", line 399, in base_process_llm_request
    responses = await llm_responses
  File "/home/matthid/proj/litellm/litellm/router.py", line 997, in acompletion
    raise e
  File "/home/matthid/proj/litellm/litellm/router.py", line 973, in acompletion
    response = await self.async_function_with_fallbacks(**kwargs)
  File "/home/matthid/proj/litellm/litellm/router.py", line 3550, in async_function_with_fallbacks
    raise original_exception
  File "/home/matthid/proj/litellm/litellm/router.py", line 3364, in async_function_with_fallbacks
    response = await self.async_function_with_retries(*args, **kwargs)
  File "/home/matthid/proj/litellm/litellm/router.py", line 3742, in async_function_with_retries
    raise original_exception
  File "/home/matthid/proj/litellm/litellm/router.py", line 3633, in async_function_with_retries
    response = await self.make_call(original_function, *args, **kwargs)
  File "/home/matthid/proj/litellm/litellm/router.py", line 3751, in make_call
    response = await response
  File "/home/matthid/proj/litellm/litellm/router.py", line 1136, in _acompletion
    raise e
  File "/home/matthid/proj/litellm/litellm/router.py", line 1095, in _acompletion
    response = await _response
  File "/home/matthid/proj/litellm/litellm/utils.py", line 1494, in wrapper_async
    raise e
  File "/home/matthid/proj/litellm/litellm/utils.py", line 1355, in wrapper_async
    result = await original_function(*args, **kwargs)
  File "/home/matthid/proj/litellm/litellm/main.py", line 544, in acompletion
    raise exception_type(
  File "/home/matthid/proj/litellm/litellm/main.py", line 525, in acompletion
    response = await init_response
  File "/home/matthid/proj/litellm/litellm/completion_extras/litellm_responses_transformation/handler.py", line 166, in acompletion
    result = await aresponses(
  File "/home/matthid/proj/litellm/litellm/utils.py", line 1494, in wrapper_async
    raise e
  File "/home/matthid/proj/litellm/litellm/utils.py", line 1355, in wrapper_async
    result = await original_function(*args, **kwargs)
  File "/home/matthid/proj/litellm/litellm/responses/main.py", line 184, in aresponses
    raise litellm.exception_type(
  File "/home/matthid/proj/litellm/litellm/litellm_core_utils/exception_mapping_utils.py", line 2271, in exception_type
    raise e
  File "/home/matthid/proj/litellm/litellm/litellm_core_utils/exception_mapping_utils.py", line 369, in exception_type
    raise BadRequestError(
litellm.exceptions.BadRequestError: litellm.BadRequestError: OpenAIException - {
  "error": {
    "message": "Invalid 'metadata': too many properties. Expected an object with at most 16 properties, but got an object with 29 properties instead.",
    "type": "invalid_request_error",
    "param": "metadata",
    "code": "object_above_max_properties"
  }
}. Received Model Group=openai/codex-mini-latest
Available Model Group Fallbacks=None LiteLLM Retried: 1 times, LiteLLM Max Retries: 2
04:55:05 - LiteLLM Proxy:DEBUG: common_request_processing.py:496 - An error occurred: litellm.BadRequestError: OpenAIException - {
  "error": {
    "message": "Invalid 'metadata': too many properties. Expected an object with at most 16 properties, but got an object with 29 properties instead.",
    "type": "invalid_request_error",
    "param": "metadata",
    "code": "object_above_max_properties"
  }
}. Received Model Group=openai/codex-mini-latest
Available Model Group Fallbacks=None LiteLLM Retried: 1 times, LiteLLM Max Retries: 2 
Model: codex-mini-latest
API Base: `https://api.openai.com`
Messages: `None`
 Debug this by setting `--debug`, e.g. `litellm --model gpt-3.5-turbo --debug`
INFO:     172.27.224.1:43633 - "POST /chat/completions HTTP/1.1" 400 Bad Request
Deployment via docker
docker run -d \
  --name $CONTAINER_NAME \
  --restart=unless-stopped \
  -v $(realpath $BASE_DIR)/data:/app/backend/data \
  --network=custom\
  --expose 8080 \
  -e "ENABLE_FORWARD_USER_INFO_HEADERS=True" \
  -e "WEBUI_SECRET_KEY=secret" \
  -e VIRTUAL_HOST=chat.mydomain \
  -e LETSENCRYPT_HOST=chat.mydomain \
  -e LETSENCRYPT_EMAIL=support@mydomain \
  -e VIRTUAL_PORT=8080 \
  -e HTTPS_METHOD=nohttp \
  ghcr.io/open-webui/open-webui:main

docker run -d \
        --name ${CONTAINER_NAME}-postgres \
        --network=custom\
        --expose 5432 \
        -e POSTGRES_PASSWORD=secret \
        -v $(realpath $BASE_DIR)/data/postgres:/var/lib/postgresql/data \
        postgres

docker build -t litellm-database:local -f $script_dir/data/litellm/docker/Dockerfile.database $script_dir/data/litellm
docker run -d \
  --name $CONTAINER_NAME \
  --restart=unless-stopped \
  -v $(realpath $BASE_DIR)/data/litellm_config.yaml:/app/config.yaml \
  --network=custom\
  --expose 4000 \
  -e "OLLAMA_API_BASE=http://madserver_ollama:11434" \
  -e "DATABASE_URL=postgresql://postgres:secret@${CONTAINER_NAME}-postgres:5432/litellm" \
  -e "LITELLM_MASTER_KEY=secret" \
  -e VIRTUAL_HOST=litellm.mydomain  \
  -e LETSENCRYPT_HOST=litellm.mydomain  \
  -e LETSENCRYPT_EMAIL=support@mydomain  \
  -e VIRTUAL_PORT=4000 \
  -e LITELLM_LOG=DEBUG \
  -e HTTPS_METHOD=nohttp \
  litellm-database:local --config /app/config.yaml --detailed_debug

Using nginxproxy/nginx-proxy and nginxproxy/acme-companion for multiple domain management and ssl.

But to be honest for debugging I just used the config, fired it up in the IDE and sent request via insomnia, pretty basic and reproduced the issue...

Full litellm_config

model_list:
  - model_name: "anthropic/*"
    litellm_params:
      model: "anthropic/*"
      api_key: "secret"
  - model_name: "ollama/*"
    litellm_params:
      model: "ollama_chat/*"
      api_base: "http://<dockerhost>:11434"
# I used this for my earlier branch/logic
#  - model_name: "openai/codex-mini-latest"
#    litellm_params:
#      model: "chat/codex-mini-latest"
#      custom_llm_provider: "chat"
#      drop_params: true
#      api_key: "secret"
  - model_name: "openai/*"
    litellm_params:
      model: "openai/*"
      api_key: "secret"
      drop_params: true
  - model_name: "gemini/*"
    litellm_params:
      model: "gemini/*"
      api_key: "secret"


litellm_settings:
  check_provider_endpoint: true


general_settings:
  user_header_name: "X-OpenWebUI-User-Email"

IIRC I'm using drop_params since I head issues somewhere else with openai not allowing the request, not related to this particular feature.

@krrishdholakia
Copy link
Contributor Author

Interesting - i'm testing claude code which uses /v1/messages and i wasn't seeing it. but switching to /chat/completions did show me the issue.

Fixing now.

krrishdholakia added a commit that referenced this pull request Jun 14, 2025
prevents optional params for responses api from including invalid args / litellm internal information

 Closes #11632 (comment)
@matthid
Copy link
Contributor

matthid commented Jun 14, 2025

@krrishdholakia cool thanks a lot! Did you also fix the Invalid value: 'input_text'. Supported values are: 'output_text' and 'refusal'." in the transformation code (a bug from my cover unfortunately, see this commit d2db195) then I'd switch to main again and hammer it a bit, there are probably some more minor things waiting, but at least the basic chatting then works ;)

krrishdholakia added a commit that referenced this pull request Jun 14, 2025
prevents optional params for responses api from including invalid args / litellm internal information

 Closes #11632 (comment)
X4tar pushed a commit to X4tar/litellm that referenced this pull request Jun 17, 2025
* refactor(responses/): refactor to move responses_to_completion in separate folder

future work to support completion_to_responses bridge

allow calling codex mini via chat completions (and other endpoints)

* Revert "refactor(responses/): refactor to move responses_to_completion in separate folder"

This reverts commit ff87cb8.

* feat: initial responses api bridge

write it like a custom llm - requires lesser 'new' components

* style: add __init__'s and bubble up the responses api bridge

* feat(responses/transformation): working sync completion -> responses and back bridge (non-streaming)

* feat(responses/): working async (non-streaming) completion <-> responses bridge

Allows calling codex mini via proxy

* feat(responses/): working sync + async streaming for base model response iterator

* fix: reduce function size

maintain <50 LOC

* fix(main.py): safely handle responses api model check

* fix: fix linting errors
X4tar pushed a commit to X4tar/litellm that referenced this pull request Jun 17, 2025
prevents optional params for responses api from including invalid args / litellm internal information

 Closes BerriAI#11632 (comment)
@matthid
Copy link
Contributor

matthid commented Jun 30, 2025

@krrishdholakia Sorry have you seen my last comment? I'm just asking to verify if I can come back to the latest build (instead of my custom version). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Question] Is codex-mini-latest (responses-API only models) supported? Add support for using Responses API in /chat/completions spec
2 participants