Skip to content

PDF sent from Telegram reaches OpenCode, but OpenAI model replies 'no PDF attached' #26

Description

@gabriel-trigo

What happened

When sending a PDF document via Telegram, the bridge detects it as a PDF, downloads it, and sends it to OpenCode as a file part (mime application/pdf, url data:application/pdf;base64,...). However the OpenAI model sometimes replies as if no PDF was attached (e.g. "I don't have the PDF file to analyze yet").

We added debug logging and confirmed the bridge is attaching the PDF correctly.

Evidence from logs

From ~/Library/Logs/opencode-telegram-bridge.log (macOS launchd):

  • Telegram document received:
    • declaredMime: application/pdf
    • inferredMime: application/pdf
    • fileSize: 2162125
  • Attachment prepared:
    • downloadedMime: application/pdf
    • byteLength: 2162125
    • dataUrl.header: data:application/pdf;base64,
    • dataUrl.payloadLength: 2882836
  • OpenCode prompt request parts:
    • { type: "text" }
    • { type: "file", mime: "application/pdf", filename: "...pdf", url: "data:application/pdf;base64,..." }
    • Model used: openai/gpt-5.2-codex

So the bridge is not dropping the PDF.

Suspected root cause

This looks like an upstream issue in how OpenCode (or its underlying provider stack) forwards PDF file parts to OpenAI, especially for models routed through the OpenAI Responses API.

Related upstream reports:

OpenAI's own docs show that data:application/pdf;base64,... is a valid format for PDF file inputs in Responses API:

Why this is a problem for this repo

We only talk to OpenCode via @opencode-ai/sdk/v2 and intentionally do NOT integrate directly with OpenAI (avoid scope creep). If OpenCode drops/ignores PDFs for OpenAI models, there is no self-contained fix here.

Repro steps

  1. Run OpenCode server: opencode serve
  2. Run this bridge as a service (launchd/systemd)
  3. Send a PDF document (no caption) to the bot
  4. Observe model reply indicating the PDF is missing

Expected

Model should be able to reference and analyze the attached PDF.

Actual

Model replies as if there is no PDF.

Notes / Workarounds

  • Switching to a non-OpenAI provider/model (e.g. Anthropic/Google) may work.
  • We do not want to implement OpenAI file uploads / file_id flow in this project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions