litellm - 💡(How to fix) Fix Get original file id in input_image [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#24797Fetched 2026-04-08 01:53:51
View on GitHub
Comments
1
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
commented ×1labeled ×1mentioned ×1subscribed ×1

Error Message

openai.BadRequestError: Error code: 400 - {'error': {'message': 'litellm.BadRequestError: OpenAIException - {\n "error": {\n "message": "Invalid 'input[0].content[0].file_id': string too long. Expected a string with maximum length 64, but got a string with length 294 instead.",\n "type": "invalid_request_error",\n "param": "input[0].content[0].file_id",\n "code": "string_above_max_length"\n }\n}. Received Model Group=gpt-5.4-nano-Promia\nAvailable Model Group Fallbacks=None', 'type': None, 'param': None, 'code': '400'}}

Root Cause

It's because its "type": "input_image" instead of "type": "input_file", , but anyways it has to be decoded, because you can send a file id of an image <img width="734" height="389" alt="image" src="https://github.com/user-attachments/assets/c5ecb19e-9795-4e7d-9b36-6ccb1cc1f124" />

Code Example

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:4000",
    api_key="sk-1234"
)

file = client.files.create(
    file=open("det-1.jpg", "rb"),
    purpose="user_data",
    extra_body={
        "target_model_names": "gpt-5.4-nano" 
    }
)

print(f"file: {file.id}")

assert file is not None

response = client.responses.create(
    model="gpt-5.4-nano",
    input=[
        {
            "role": "user",
            "content": [
                {
                    "type": "input_image",
                    "file_id": file.id,
                },
                {
                    "type": "input_text",
                    "text": "que ves en el fichero?",
                },
            ]
        }
    ]
)

print(response)

---

openai.BadRequestError: Error code: 400 - {'error': {'message': 'litellm.BadRequestError: OpenAIException - {\n  "error": {\n    "message": "Invalid \'input[0].content[0].file_id\': string too long. Expected a string with maximum length 64, but got a string with length 294 instead.",\n    "type": "invalid_request_error",\n    "param": "input[0].content[0].file_id",\n    "code": "string_above_max_length"\n  }\n}. Received Model Group=gpt-5.4-nano-Promia\nAvailable Model Group Fallbacks=None', 'type': None, 'param': None, 'code': '400'}}
RAW_BUFFERClick to expand / collapse

This is failing:

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:4000",
    api_key="sk-1234"
)

file = client.files.create(
    file=open("det-1.jpg", "rb"),
    purpose="user_data",
    extra_body={
        "target_model_names": "gpt-5.4-nano" 
    }
)

print(f"file: {file.id}")

assert file is not None

response = client.responses.create(
    model="gpt-5.4-nano",
    input=[
        {
            "role": "user",
            "content": [
                {
                    "type": "input_image",
                    "file_id": file.id,
                },
                {
                    "type": "input_text",
                    "text": "que ves en el fichero?",
                },
            ]
        }
    ]
)

print(response)
openai.BadRequestError: Error code: 400 - {'error': {'message': 'litellm.BadRequestError: OpenAIException - {\n  "error": {\n    "message": "Invalid \'input[0].content[0].file_id\': string too long. Expected a string with maximum length 64, but got a string with length 294 instead.",\n    "type": "invalid_request_error",\n    "param": "input[0].content[0].file_id",\n    "code": "string_above_max_length"\n  }\n}. Received Model Group=gpt-5.4-nano-Promia\nAvailable Model Group Fallbacks=None', 'type': None, 'param': None, 'code': '400'}}

It's because its "type": "input_image" instead of "type": "input_file", , but anyways it has to be decoded, because you can send a file id of an image <img width="734" height="389" alt="image" src="https://github.com/user-attachments/assets/c5ecb19e-9795-4e7d-9b36-6ccb1cc1f124" />

Originally posted by @rodriciru in https://github.com/BerriAI/litellm/issues/16733#issuecomment-4155991108

extent analysis

Fix Plan

To fix the issue, we need to change the type from "input_image" to "input_file" and decode the file ID.

Code Changes

Here are the steps to fix the code:

  • Change the type from "input_image" to "input_file" in the content list.
  • Decode the file ID before sending it in the request.
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:4000",
    api_key="sk-1234"
)

file = client.files.create(
    file=open("det-1.jpg", "rb"),
    purpose="user_data",
    extra_body={
        "target_model_names": "gpt-5.4-nano" 
    }
)

print(f"file: {file.id}")

assert file is not None

response = client.responses.create(
    model="gpt-5.4-nano",
    input=[
        {
            "role": "user",
            "content": [
                {
                    "type": "input_file",
                    "file_id": file.id,
                },
                {
                    "type": "input_text",
                    "text": "que ves en el fichero?",
                },
            ]
        }
    ]
)

print(response)

Verification

To verify that the fix worked, check the response from the client.responses.create method. If the response is successful, it should contain the expected output from the model.

Extra Tips

Make sure to handle any exceptions that may occur during the file creation or response creation process. Additionally, ensure that the file ID is valid and the model is configured correctly to accept file inputs.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING