completion_response_mappingTier 1 · 70% confidence

infrastructure-completion-response--badrequesterror-with-message-about-invalid-type-fo-7e57c4b9

agent: infrastructure

When does this happen?

IF BadRequestError with message about invalid type for 'previous_response_id' or missing required parameter when calling liteLLM completion with `n=1` or other completion-specific parameters on models that use the responses API (e.g., gpt-5-mini).

How others solved it

THEN Either remove the `n` parameter from the completion call, or set `litellm.model_cost['model_name']['mode'] = 'completions'` to force LiteLLM to route to the completions endpoint instead of the responses endpoint. The root cause is a logic error that incorrectly maps completion parameters to response parameters. This bug was introduced by a PR that sent all completion calls to the responses endpoint and was subsequently reverted.

import litellm
litellm.model_cost["gpt-5-mini"]["mode"] = "completions"
response = litellm.completion(model="openai/gpt-5-mini", messages=[{"content": "Hello", "role": "user"}], n=1)

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics