镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

ollama: attaching a file does not work/results in error 500/400 Bad request #11

Open

Description

@nodiscc

Steps to reproduce:

  • llms --serve 8080 --verbose, access web UI
  • select ollama provider (tested with multiple models)
  • attach a file (tested with multiple text files/shell/python scripts) with a promt su chas Please summarize this document and submit the query
  • the web UI displays an error and not response is returned
HTTP 500 Internal Server Error
{
  "error": "HTTP 400 Bad Request"
}

Logs:

provider: ollama OllamaProvider
POST http://localhost:11434/v1/chat/completions
{
  "model": "deepseek-r1:14b",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "file",
          "file": {
            "filename": "test.xml",
            "file_data": "data:text/xml;base64,(1325)"
          }
        },
        {
          "type": "text",
          "text": "Summarize the file\n\n[\ud83d\udcce test.xml]"
        }
      ]
    }
  ],
  "enable_thinking": true,
  "metadata": {
    "threadId": "1765739448549"
  },
  "stream": false
}
Provider ollama failed: HTTP 400 Bad Request

Activity

  1. nodiscc commented on Dec 14, 2025

    @nodiscc
    Author

    Interestingly, attaching an image file and asking the ollama model to describe it works as expected.
    I see it uses "type": "image_url" instead of "type": "file"

    Details
    provider: ollama OllamaProvider
    Resized image from 1754x1403 to 1280x1024
    Converted image to WebP: 798373 bytes -> 235210 bytes (29%)
    POST http://localhost:11434/v1/chat/completions
    {
      "model": "qwen3-vl:8b",
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "image_url",
              "image_url": {
                "url": "data:image/webp;base64,(313617)"
              }
            },
            {
              "type": "text",
              "text": "Describe the key features of the input image\n\n[\ud83d\uddbc\ufe0f Snowden_Slights_with_big_gun_YORYM-S364.jpg]"
            }
          ]
        }
      ],
      "enable_thinking": true,
      "metadata": {
        "threadId": "1765745070478"
      },
      "stream": false
    }
    {
      "id": "chatcmpl-198",
      "object": "chat.completion",
      "created": 1765745083,
      "model": "qwen3-vl:8b",
      "system_fingerprint": "fp_ollama",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "This black - and - white photograph presents a historical scene with several prominent features:  [...].",
            "reasoning": "So, let's describe the key features of this black-and-white photograph. [...]."
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 1328,
        "completion_tokens": 687,
        "total_tokens": 2015
      },
      "metadata": {
        "duration": 12785,
        "pricing": "0/0"
      }
    }
  2. nodiscc commented on Dec 14, 2025

    @nodiscc
    Author
          "content": [
            {
              "type": "file",
              "file": {
                "filename": "test.xml",
                "file_data": "data:text/xml;base64,(1325)"
              }

    I don't think this is supposed to be supported at all by the API (https://docs.ollama.com/api/openai-compatibility), am I correct? This issue seems to support my conclusion ollama/ollama#5762

    I think the only correct way to achieve this, would be to have llms.py extract the content of the file and pass it to the LLM through the prompt.

  3. mythz commented on Dec 15, 2025

    @mythz
    Member

    I can't find any official way that Ollama supports to send file attachments like PDFs, the standard OpenAI compatible way works if I call the same model on OpenRouter (e.g. Gemma 3n 4B) so I don't think it's supported.

    I'll wait for official support from Ollama, which I expect will just be to implement OpenAI's file type support, like they do with image_url when they added support for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions