marimo icon indicating copy to clipboard operation
marimo copied to clipboard

DeepSeek API incompatible with AI chat - content format error after first message

Open evgspacdmy opened this issue 1 month ago • 1 comments

When using DeepSeek API (https://api.deepseek.com) with marimo's built-in AI assistant chat panel, the first message works but subsequent messages fail with:

Error code: 400 - {'error': {'message': "Failed to deserialize the JSON body into the target type: messages[2]: invalid type: sequence, expected a string at line 1 column 14163", 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}

Root cause: Marimo sends message content in array format with 'parts' structure, but DeepSeek API only accepts simple string content for the message content field.

Configuration used: [ai.open_ai] api_key = "sk-..." model = "deepseek-chat" base_url = "https://api.deepseek.com"


**Steps to reproduce:**
  1. Configure marimo with DeepSeek API credentials
  2. Open AI chat panel in editor
  3. Send first message - works fine
  4. Send second message - fails with above error

**Expected behavior:**

Multi-turn conversations should work with DeepSeek API, as it claims OpenAI compatibility


<img width="1234" height="1404" alt="Image" src="https://github.com/user-attachments/assets/38562ad3-e531-4e3c-a778-94bdd7e4ea09" />


**Additional context:**

Similar issue reported with other tools (Claude Code, LiteLLM) where DeepSeek's partial OpenAI compatibility causes content format errors.

Suggested fix: When base_url contains "api.deepseek.com", ensure message content is sent as string rather than array format.

evgspacdmy avatar Nov 02 '25 21:11 evgspacdmy

I'd like to contribute

Nihir2904 avatar Nov 03 '25 20:11 Nihir2904