litellm - 💡(How to fix) Fix [Bug]: Cloudflare Workers AI returns empty content for OpenAI-style result.choices[0].message.content responses [2 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

Because of this, models that return content through:

Fix Action

Fixed

Code Example

{
  "result": {
    "choices": [
      {
        "message": {
          "content": "..."
        }
      }
    ]
  }
}

---

completion_response["result"]["response"]

---

result["choices"][0]["message"]["content"]

---

completion_response["result"]["choices"][0]["message"]["content"]

---

completion_response["result"]["response"]

---

result["choices"][0]["message"]["content"]

---

model_list:
  - model_name: cloudflare-kimi
    litellm_params:
      model: cloudflare/@cf/moonshotai/kimi-k2-instruct
      api_key: os.environ/CLOUDFLARE_API_KEY
      account_id: os.environ/CLOUDFLARE_ACCOUNT_ID

---

litellm --config config.yaml

---

curl http://localhost:4000/v1/chat/completions \
  -H "Authorization: Bearer $LITELLM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cloudflare-kimi",
    "messages": [
      {
        "role": "user",
        "content": "Say hello in one sentence."
      }
    ]
  }'

---

{
  "result": {
    "choices": [
      {
        "message": {
          "role": "assistant",
          "content": "Hello! How can I help you today?"
        }
      }
    ]
  },
  "success": true,
  "errors": [],
  "messages": []
}

---

result["choices"][0]["message"]["content"]

---

result["response"]

---
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

What happened?

I am using LiteLLM as the gateway layer in an AI Harness system.

While testing Cloudflare Workers AI models through LiteLLM, I found that some newer Cloudflare models return content in an OpenAI-compatible response shape:

{
  "result": {
    "choices": [
      {
        "message": {
          "content": "..."
        }
      }
    ]
  }
}

However, LiteLLM's Cloudflare response parser appears to read only the legacy Cloudflare shape:

completion_response["result"]["response"]

Because of this, models that return content through:

result["choices"][0]["message"]["content"]

do not get parsed correctly by LiteLLM. The direct Cloudflare API call returns valid content, but LiteLLM returns an empty response / no content.

Affected models

I reproduced this with newer Cloudflare Workers AI models, including:

  • Kimi K-2.6
  • GLM
  • Gemma-4-26B

All three return content correctly when called directly through Cloudflare, but LiteLLM does not surface the content correctly.

Expected behavior

LiteLLM should parse the response content from the newer OpenAI-style Cloudflare response shape:

completion_response["result"]["choices"][0]["message"]["content"]

If the legacy Cloudflare field is present, LiteLLM can continue using:

completion_response["result"]["response"]

But if result.response is missing, it should fall back to result.choices[0].message.content.

Actual behavior

LiteLLM's Cloudflare handler expects the legacy result.response field.

For newer models returning OpenAI-style responses, LiteLLM does not fall back to result.choices[0].message.content, so the response content becomes empty / missing.

Why I think this is a LiteLLM parsing bug

Direct Cloudflare API calls return valid content for all tested models.

The response content exists at:

result["choices"][0]["message"]["content"]

So the issue is not with Cloudflare model generation. The issue appears to be in LiteLLM's Cloudflare response transformation/parsing layer.

Related issues

This may be related to existing Cloudflare Workers AI issues:

  • #25999
  • #24065

Steps to Reproduce

  1. Configure LiteLLM with a Cloudflare Workers AI model that returns an OpenAI-style response shape.

Example config.yaml:

model_list:
  - model_name: cloudflare-kimi
    litellm_params:
      model: cloudflare/@cf/moonshotai/kimi-k2-instruct
      api_key: os.environ/CLOUDFLARE_API_KEY
      account_id: os.environ/CLOUDFLARE_ACCOUNT_ID
  1. Start the LiteLLM proxy:
litellm --config config.yaml
  1. Send a chat completion request through LiteLLM:
curl http://localhost:4000/v1/chat/completions \
  -H "Authorization: Bearer $LITELLM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cloudflare-kimi",
    "messages": [
      {
        "role": "user",
        "content": "Say hello in one sentence."
      }
    ]
  }'
  1. Observe that LiteLLM returns an empty or missing assistant content.

  2. Call the same Cloudflare model directly using the Cloudflare Workers AI API.

Example response shape from Cloudflare:

{
  "result": {
    "choices": [
      {
        "message": {
          "role": "assistant",
          "content": "Hello! How can I help you today?"
        }
      }
    ]
  },
  "success": true,
  "errors": [],
  "messages": []
}
  1. Notice that the model output exists at:
result["choices"][0]["message"]["content"]

but LiteLLM's Cloudflare parser expects the legacy field:

result["response"]
  1. Because LiteLLM does not fall back to result.choices[0].message.content, the response content is not parsed correctly.

Relevant log output

What part of LiteLLM is this about?

SDK (litellm Python package)

What LiteLLM version are you on ?

v1.86.2

Twitter / LinkedIn details

@PiyushAryanPA

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

LiteLLM should parse the response content from the newer OpenAI-style Cloudflare response shape:

completion_response["result"]["choices"][0]["message"]["content"]

If the legacy Cloudflare field is present, LiteLLM can continue using:

completion_response["result"]["response"]

But if result.response is missing, it should fall back to result.choices[0].message.content.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]: Cloudflare Workers AI returns empty content for OpenAI-style result.choices[0].message.content responses [2 pull requests]