[GH-ISSUE #7236] The response data is not compatiable with OpenAI API. #82275

Closed
opened 2026-05-09 13:36:11 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @tobegit3hub on GitHub (Oct 17, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/7236

Refer to the API docs in https://github.com/ollama/ollama/blob/main/docs/api.md , currently the response data format is not compatible with OpenAI API.

image

It is import to be compatible with OpenAI API for not only the request data but also the response data. Is there any plan to make changes for response data?

Originally created by @tobegit3hub on GitHub (Oct 17, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/7236 Refer to the API docs in https://github.com/ollama/ollama/blob/main/docs/api.md , currently the response data format is not compatible with OpenAI API. <img width="1067" alt="image" src="https://github.com/user-attachments/assets/29274088-f365-4881-a3c9-b814eb74e3c3"> It is import to be compatible with OpenAI API for not only the request data but also the response data. Is there any plan to make changes for response data?
GiteaMirror added the feature request label 2026-05-09 13:36:11 -05:00
Author
Owner

@rick-github commented on GitHub (Oct 17, 2024):

Use the OpenAI compatibility endpoint.

<!-- gh-comment-id:2418750417 --> @rick-github commented on GitHub (Oct 17, 2024): Use the [OpenAI compatibility endpoint](https://github.com/ollama/ollama/blob/main/docs/openai.md).
Author
Owner

@tobegit3hub commented on GitHub (Oct 17, 2024):

Use the OpenAI compatibility endpoint.

Thanks for replying. Actually we are using this compatibility endpoint. But the response is not compatible with official OpenAI API which is also supported by vllm. Here is the expected response data. Refer to https://platform.openai.com/docs/api-reference/streaming .

image
<!-- gh-comment-id:2418773983 --> @tobegit3hub commented on GitHub (Oct 17, 2024): > Use the [OpenAI compatibility endpoint](https://github.com/ollama/ollama/blob/main/docs/openai.md). Thanks for replying. Actually we are using this compatibility endpoint. But the response is not compatible with official OpenAI API which is also supported by `vllm`. Here is the expected response data. Refer to https://platform.openai.com/docs/api-reference/streaming . <img width="870" alt="image" src="https://github.com/user-attachments/assets/f9dada47-6564-4855-8f61-435bb24e7436">
Author
Owner

@rick-github commented on GitHub (Oct 17, 2024):

What is incompatible about the ollama response?

<!-- gh-comment-id:2418785277 --> @rick-github commented on GitHub (Oct 17, 2024): What is incompatible about the ollama response?
Author
Owner

@tobegit3hub commented on GitHub (Oct 17, 2024):

What is incompatible about the ollama response?

The expected response should be like this.

{
    "id": "chatcmpl-abc123",
    "object": "chat.completion",
    "created": 1677858242,
    "model": "gpt-4o-mini",
    "usage": {
        "prompt_tokens": 13,
        "completion_tokens": 7,
        "total_tokens": 20,
        "completion_tokens_details": {
            "reasoning_tokens": 0
        }
    },
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "\n\nThis is a test!"
            },
            "logprobs": null,
            "finish_reason": "stop",
            "index": 0
        }
    ]
}

But the actual response from ollama is like this.

{
  "model": "codellama:code",
  "created_at": "2024-07-22T20:47:51.147561Z",
  "response": "\n  if a == 0:\n    return b\n  else:\n    return compute_gcd(b % a, a)\n\ndef compute_lcm(a, b):\n  result = (a * b) / compute_gcd(a, b)\n",
  "done": true,
  "done_reason": "stop",
  "context": [...],
  "total_duration": 1162761250,
  "load_duration": 6683708,
  "prompt_eval_count": 17,
  "prompt_eval_duration": 201222000,
  "eval_count": 63,
  "eval_duration": 953997000
}

The streamming mode has the same issue as well.

Our applicaitons will use public model service which is completely compatiable with OpenAI API and ollama model services. The difference of their response require extra work for applications to handle.

<!-- gh-comment-id:2418860360 --> @tobegit3hub commented on GitHub (Oct 17, 2024): > What is incompatible about the ollama response? The expected response should be like this. ``` { "id": "chatcmpl-abc123", "object": "chat.completion", "created": 1677858242, "model": "gpt-4o-mini", "usage": { "prompt_tokens": 13, "completion_tokens": 7, "total_tokens": 20, "completion_tokens_details": { "reasoning_tokens": 0 } }, "choices": [ { "message": { "role": "assistant", "content": "\n\nThis is a test!" }, "logprobs": null, "finish_reason": "stop", "index": 0 } ] } ``` But the actual response from ollama is like this. ``` { "model": "codellama:code", "created_at": "2024-07-22T20:47:51.147561Z", "response": "\n if a == 0:\n return b\n else:\n return compute_gcd(b % a, a)\n\ndef compute_lcm(a, b):\n result = (a * b) / compute_gcd(a, b)\n", "done": true, "done_reason": "stop", "context": [...], "total_duration": 1162761250, "load_duration": 6683708, "prompt_eval_count": 17, "prompt_eval_duration": 201222000, "eval_count": 63, "eval_duration": 953997000 } ``` The streamming mode has the same issue as well. Our applicaitons will use public model service which is completely compatiable with OpenAI API and ollama model services. The difference of their response require extra work for applications to handle.
Author
Owner

@rick-github commented on GitHub (Oct 17, 2024):

That response is from the ollama API endpoint, /api/generate. Use the OpenAI compatibility endpoint, /v1/chat/completions.

<!-- gh-comment-id:2418875636 --> @rick-github commented on GitHub (Oct 17, 2024): That response is from the ollama API endpoint, `/api/generate`. Use the [OpenAI compatibility endpoint](https://github.com/ollama/ollama/blob/main/docs/openai.md), `/v1/chat/completions`.
Author
Owner

@tobegit3hub commented on GitHub (Oct 17, 2024):

That response is from the ollama API endpoint, /api/generate. Use the OpenAI compatibility endpoint, /v1/chat/completions.

Thanks and you are right. We are using the incoreect API and the /v1/chat/completions works like a charm. Thanks and I will close this issue.

<!-- gh-comment-id:2418959686 --> @tobegit3hub commented on GitHub (Oct 17, 2024): > That response is from the ollama API endpoint, `/api/generate`. Use the [OpenAI compatibility endpoint](https://github.com/ollama/ollama/blob/main/docs/openai.md), `/v1/chat/completions`. Thanks and you are right. We are using the incoreect API and the `/v1/chat/completions` works like a charm. Thanks and I will close this issue.
Author
Owner

@chuanSir123 commented on GitHub (Feb 8, 2025):

The streamming mode has no usage!!!!

<!-- gh-comment-id:2644514935 --> @chuanSir123 commented on GitHub (Feb 8, 2025): The streamming mode has no usage!!!!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#82275