Hosted ChatKit 500 when sending image attachment (PNG) via threads.add_user_message

Environment

  • Hosted ChatKit workflow (OpenAI-managed /v1/chatkit/*)

  • Custom app uploads screenshots to its own /api/chatkit/files for GPT Vision Analysis, returns ImageAttachment objects ({ id, type: “image”, mime_type: “image/png”, preview_url: “/api/chatkit/attachments/” })

  • Attachments served via FastAPI (Agents SDK) with both GET and HEAD implemented and exposed through ngrok

  • Screenshot pipeline: BPMN modeler.saveSVG() → svgToPng() → → canvas.toDataURL(‘image/png’) → uploaded as PNG

Steps to Reproduce

  1. Opening the hosted ChatKit panel in my app.

  2. Clicking the “Screenshot” button (calls sendCanvasToChat → ui:ai:attachImage).

  3. The client POSTs to our upload proxy:

POST https://procmod.test:3000/api/chatkit/files
→ 200
→ body:
{
"attachment": {
"id": "atc_14d17d71",
"type": "image",
"mime_type": "image/png",
"name": "Canvas-Snapshot.png",
"preview_url": "https://xxxxxxx.dev/api/chatkit/attachments/atc_14d17d71",
"upload_url": null
}
}

  1. ChatKit immediately calls threads.add_user_message with that attachment:

POST https://api.openai.com/v1/chatkit/conversation
{
"type": "threads.add_user_message",
"params": {
"input": {
"content": [
{ "type": "input_text", "text": "Canvas Snapshot" }
],
"quoted_text": "",
"attachments": ["atc_14d17d71"],
"inference_options": {}
},
"thread_id": "cthr_691d7fe35bdc81949f95d4b876b69b43028e75a668a6dd4a"
}
}

  1. Response is always HTTP 500 with the generic error, no additional information in the hosted iframe (CORS hides it):

HTTP/1.1 500 Internal Server Error
x-request-id: 60eeacec-707a-4443-a084-b87abcdcb7b4
(open latest curl replay → `x-request-id: b49053e4-7b94-4167-b278-2f34e86b8de1`)
Body:
{
"error": {
"message": "The server had an error processing your request...",
"type": "server_error"
}
}

  1. We verified this outside the browser by replaying the same payload via curl with a fresh client_secret (from /api/chatkit/refresh). Result is the same 500:

curl -i https://api.openai.com/v1/chatkit/conversation \
-H "Authorization: Bearer <new client_secret>" \
-H "Content-Type: application/json" \
--data '{"type":"threads.add_user_message", ... }'

→ HTTP/2 500
→ x-request-id: b49053e4-7b94-4167-b278-2f34e86b8de1

What we checked

  • The attachment preview URL is public and responds to both HEAD and GET (tested via curl).

  • Content-Type returned by our upload endpoint is image/png.

  • The pipeline never uploads SVGs; the only image/svg+xml request is the local blob: render prior to canvas.toDataURL(‘image/png’).

  • Fresh client_secrets fail as well; we see expired_ephemeral_key only when reusing old ones.

  • Text-only conversations on the same thread succeed (HTTP 200). The failure happens only when attachments includes our PNG id.

Expected

Hosted ChatKit should include the attachment and let the agent continue responding. If the attachment can’t be fetched or the format is unsupported, we expect a clear error (4xx with message) instead of a 500 with no body.

Actual

Call to /v1/chatkit/conversation fails with HTTP 500 and server_error regardless of attachment reachability. The iframe shows the generic “Beim Generieren … ist ein Fehler aufgetreten” error and the turn aborts. We have multiple request ids documenting the failure (60eeacec-707a-4443-a084-b87abcdcb7b4, b49053e4-7b94-4167-b278-2f34e86b8de1).

Questions

  • Is mixing hosted ChatKit conversations with custom /api/chatkit/files uploads supported? Docs describe the ImageAttachment shape but don’t mention restrictions when the storage lives on our own server.

  • If the attachment fails validation, could the hosted pipeline return a specific error instead of a generic 500?

  • What additional logging or request ids do you need to investigate

Bump… anyone else had this error before? tried a few different things but always had the same error message. All I am trying to do is automatically attach an image after a button is pressed, when sending a chat message via ChatKit

Hi there! Thanks for reporting. I am trying to investigate / replicate the issue you’re seeing. I haven’t been able to yet, but the underlying issue I see from one of these request IDs you shared (thanks!) is ultimately that the user object that created the thread is not the same as the user of the current Session:

  • Thread user: web-<uuid>
  • Session user creating new item: cli-debugger

This may have been a result of the aforementioned debugging you were trying (this was for request ID b49053e4-7b94-4167-b278-2f34e86b8de1). I can try to look up a request ID on an attempt that might not be split like this above. But that said, the user must always be consistent across Sessions if you plan to access the same data.

The more fundamental issue appears to be “ChatKit File with id ‘atc_14d17d71’ not found” – I see you mention proxying file uploads to a separate store. I fundamentally do not think that will work, as there is an expectation that all files live inside our own stores.

If custom image persistence/serving is important for your use case, my recommendation is to host your own backend for chatkit rather than using our hosted version of the product.

1 Like

Thank you very much for replying first of all!
So you were right and I switched to an entirely Self-Hosted Chatkit in the last few days which was not so easy.
But now after many iterative fix attempts it finally works and I can upload an image of the current canvas directly to chatkit via a button so it can be visually analyzed for context.

The only minor annoyance left is that the image is not displayed as a photo in the preview above the chat, but as a file type. The preview renders correctly once the message is sent though so whatever, maybe I’ll be able to fix it.

Attached is also the log of the final session of fixes via Chatkit, if you want to analyze it / somehow has the same issue and finds this thread. If you want the complete Log of the many many other fixes that came before this, feel free to reach out :slight_smile: