Skip to content

AiError: Bad input when using Cloudflare Workers AI — message content format mismatch #30381

Closed as not planned

Description

@Taimoorkhan1122

Description

Bug Description

Selecting any Cloudflare Workers AI model causes AiError: Bad input with schema validation failure. Messages are sent with inconsistent content field types in the same request.

Error

Bad Request: {"errors":{"message":"AiError: Bad input: Error: oneOf at '/' not met, 0 matches: required properties at '/' are 'prompt', Type mismatch of '/messages/0/content', 'array' not in 'string', Type mismatch of '/messages/1/content', 'string' not in 'array', required properties at '/messages/1' are 'role,content' (d9e09afe-fe49-4051-bc1d-8901f858ff52)","code":5006},"success":false,"result":{},"messages":[]}

Root Cause

A mix of Anthropic-style and OpenAI-style message formats in the same request:

  • Some messages have content as an array ([{type: "text", text: "..."}])
  • Others have content as a string ("...")
    Cloudflare Workers AI expects OpenAI-compatible schema where content type is consistent.

To Reproduce

  1. Configure opencode with Cloudflare Workers AI as provider
  2. Select any Cloudflare Workers AI model
  3. Start a conversation — error appears immediately

Environment

  • opencode version: 1.15.5 (Homebrew)
  • Provider: Cloudflare Workers AI
  • Platform: macOS
  • No custom system prompt

Plugins

superpowers

OpenCode version

1.15.13

Steps to reproduce

  1. Configure opencode with Cloudflare Workers AI as provider
  2. Select any Cloudflare Workers AI model
  3. Start a conversation — error appears immediately

Screenshot and/or share link

Image

Operating System

macOS 26.4.1 (25E253)

Terminal

Terminal

Activity

  1. ulises-jeremias commented on Jun 3, 2026

    @ulises-jeremias
    Contributor

    I’d like to take this one. I’ll trace the Cloudflare Workers AI request formatting path, reproduce the mixed message content shape (text string vs content array), and open a focused fix with regression tests.

  2. ulises-jeremias commented on Jun 3, 2026

    @ulises-jeremias
    Contributor

    Opened a fix PR with regression tests:

    It normalizes Cloudflare Workers AI mixed message content shapes (string + text-part arrays) into a consistent string form when safe, while preserving tool/non-text arrays unchanged.

  3. daton89 commented on Jun 10, 2026

    @daton89

    I've the same issue, @ulises-jeremias thanks for fixing it...
    when do you plan to release it?

  4. ulises-jeremias commented on Jun 12, 2026

    @ulises-jeremias
    Contributor

    I've the same issue, @ulises-jeremias thanks for fixing it... when do you plan to release it?

    @nexxeln do you mind taking a look to this PR with the fix? #30589 👀

  5. steelx commented on Jul 7, 2026

    @steelx

    any fix ?

  6. steelx commented on Jul 14, 2026

    @steelx
    {
      "name": "AiError",
      "internalCode": 5006,
      "httpCode": 400,
      "message": "AiError: Bad input: Error: oneOf at '/' not met, 0 matches: required properties at '/' are 'prompt', Type mismatch of '/messages/0/content', 'array' not in 'string', Type mismatch of '/messages/1/content', 'array' not in 'string', Type mismatch of '/messages/2/content', 'string' not in 'array', required properties at '/messages/2' are 'role,content', oneOf at '/' not met, 0 matches, required properties at '/' are 'input', required properties at '/' are 'requests' (a8e8e150-2ec6-4022-8c54-71e8e72eec57)",
      "description": "Error: oneOf at '/' not met, 0 matches: required properties at '/' are 'prompt', Type mismatch of '/messages/0/content', 'array' not in 'string', Type mismatch of '/messages/1/content', 'array' not in 'string', Type mismatch of '/messages/2/content', 'string' not in 'array', required properties at '/messages/2' are 'role,content', oneOf at '/' not met, 0 matches, required properties at '/' are 'input', required properties at '/' are 'requests'",
      "requestId": "a8e8e150-2ec6-4022-8c54-71e8e72eec57"
    }
    
  7. ulises-jeremias commented on Jul 14, 2026

    @ulises-jeremias
    Contributor

    @steelx I just opened a new PR with the fix: #36850

    The previous PR (#30589) was closed by the automated cleanup bot due to age and lack of reactions, but the fix is the same — normalizing mixed content types for cloudflare-workers-ai messages.

    @nexxeln could you please take a look when you get a chance? Thanks!

  8. steelx commented on Jul 17, 2026

    @steelx

    @steelx I just opened a new PR with the fix: #36850

    The previous PR (#30589) was closed by the automated cleanup bot due to age and lack of reactions, but the fix is the same — normalizing mixed content types for cloudflare-workers-ai messages.

    @nexxeln could you please take a look when you get a chance? Thanks!

    hey this looks good. and it gave me idea.. even if they dont approve PR we can use caveman like transformer here and inject it as plugin to enhance the output into string.

  9. github-actions commented on Sep 17, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  10. kawpii commented on Sep 27, 2026

    @kawpii

    Still get following with Cloudflare Workers AI:

    Bad Request: {"errors":[{"message":"AiError: Bad input: Error: oneOf at '/' not met, 0 matches: required properties at '/' are 'prompt', Type mismatch of '/messages/0/content', 'array' not in 'string', Type mismatch of '/messages/1/content', 'string' not in 'array', required properties at '/messages/1' are 'role,content', oneOf at '/' not met, 0 matches, required properties at '/' are 'input', required properties at '/' are 'requests' (802fcf5e-949a-4ad1-bf8b-608bb83ae5d6)","code":5006}],"success":false,"result":{},"messages":[]}
    

    Cloudlfare Workers Gateway did not work either.

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

Metadata

Metadata

Assignees

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