openai_api_compatible used fail in rag #658

Closed
opened 2026-02-16 10:20:06 -05:00 by yindo · 1 comment
Owner

Originally created by @SquirrelJimmy on GitHub (Sep 20, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues Dify issues & Dify Official Plugins, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.8.1

Plugin version

0.0.22

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

add a openai_api_compatible embedding model, can not use in rag

✔️ Error log

core.model_runtime.errors.invoke.InvokeError: [openai_api_compatible] Error: req_id: bee503fce8 PluginInvokeError: {"args":{"description":"[models] Error: 'usage'"},"error_type":"InvokeError","message":"[models] Error: 'usage'"}

Originally created by @SquirrelJimmy on GitHub (Sep 20, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [Dify issues](https://github.com/langgenius/dify/issues) & [Dify Official Plugins](https://github.com/langgenius/dify-official-plugins/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.8.1 ### Plugin version 0.0.22 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce add a openai_api_compatible embedding model, can not use in rag ### ✔️ Error log core.model_runtime.errors.invoke.InvokeError: [openai_api_compatible] Error: req_id: bee503fce8 PluginInvokeError: {"args":{"description":"[models] Error: 'usage'"},"error_type":"InvokeError","message":"[models] Error: 'usage'"}
yindo added the bug label 2026-02-16 10:20:06 -05:00
yindo closed this issue 2026-02-16 10:20:06 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 20, 2025):

The error [models] Error: 'usage' means your embedding model's response is missing the required usage field. Dify expects OpenAI-compatible embedding responses to include a usage object with prompt_tokens and total_tokens. For example:

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [ ... ],
      "index": 0
    }
  ],
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}

If your model response doesn't have this exact structure, Dify will fail to use it in RAG workflows and throw the error you saw. Make sure your embedding API returns the usage field as shown above, even if you have to hardcode reasonable values for testing. This requirement is enforced in recent Dify and plugin versions, and similar issues have been reported by other users here.

If you update your model or proxy to return the correct format, the error should resolve. If you use a third-party provider, check their docs or wrapper for OpenAI compatibility and response structure.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Sep 20, 2025): <!-- Answer --> The error `[models] Error: 'usage'` means your embedding model's response is missing the required `usage` field. Dify expects OpenAI-compatible embedding responses to include a `usage` object with `prompt_tokens` and `total_tokens`. For example: ```json { "object": "list", "data": [ { "object": "embedding", "embedding": [ ... ], "index": 0 } ], "usage": { "prompt_tokens": 8, "total_tokens": 8 } } ``` If your model response doesn't have this exact structure, Dify will fail to use it in RAG workflows and throw the error you saw. Make sure your embedding API returns the `usage` field as shown above, even if you have to hardcode reasonable values for testing. This requirement is enforced in recent Dify and plugin versions, and similar issues have been reported by other users [here](https://github.com/langgenius/dify-official-plugins/issues/1404). If you update your model or proxy to return the correct format, the error should resolve. If you use a third-party provider, check their docs or wrapper for OpenAI compatibility and response structure. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/57f658da-7196-44e5-a888-f8f461ef8cc0?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/57f658da-7196-44e5-a888-f8f461ef8cc0?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/57f658da-7196-44e5-a888-f8f461ef8cc0?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/57f658da-7196-44e5-a888-f8f461ef8cc0?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/57f658da-7196-44e5-a888-f8f461ef8cc0?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/57f658da-7196-44e5-a888-f8f461ef8cc0?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/57f658da-7196-44e5-a888-f8f461ef8cc0?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify-official-plugins/issues/1741)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#658