Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing prompt_tokens and total_tokens in Usage Object Returned in DeepSeek Model #858

Open
k99k5 opened this issue Jan 8, 2025 · 4 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers triage

Comments

@k99k5
Copy link

k99k5 commented Jan 8, 2025

What Happened?

{
    "id": "74196500-8b9b-475a-aab3-381cec604587",
    "object": "chat.completion.chunk",
    "created": 1736352401,
    "choices": [
      {
        "index": 0,
        "finish_reason": "stop",
        "message": {
          "role": "assistant",
          "content": "\nif (isset($_POST['like'])) {\n    echo 'Thank you for your support!';\n}\n?>\n"
        }
      }
    ],
    "model": "deepseek-chat",
    "usage": {
      "completion_tokens": 25
    }
  }

What Should Have Happened?

The official API returns the following response:

{"id":"577145fa-34cb-4cc4-b937-6f8e03eafa79","object":"chat.completion.chunk","created":1736355607,"model":"deepseek-chat","system_fingerprint":"fp_3a5770e1b4","choices":[{"index":0,"delta":{"content":""},"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":9,"completion_tokens":11,"total_tokens":20,"prompt_cache_hit_tokens":0,"prompt_cache_miss_tokens":9}}

Relevant Code Snippet

No response

Your Twitter/LinkedIn

No response

@k99k5 k99k5 added the bug Something isn't working label Jan 8, 2025
@github-actions github-actions bot added the triage label Jan 8, 2025
@k99k5 k99k5 changed the title Missing prompt_tokens and total_tokens in Usage Object Returned by Cache in DeepSeek Model Missing prompt_tokens and total_tokens in Usage Object Returned in DeepSeek Model Jan 8, 2025
@narengogi narengogi added the good first issue Good for newcomers label Jan 10, 2025
@narengogi
Copy link
Collaborator

narengogi commented Jan 15, 2025

Thanks for reporting this @k99k5
This should be pretty straightforward to fix

@narengogi
Copy link
Collaborator

Hey @k99k5 I'm able to see the prompt_tokens in response for deepseek-chat model used through the gateway, can you provide a sample cURL that is not working for you?

request

curl --location 'https://api.portkey.ai/v1/chat/completions' \
--header 'x-portkey-provider: deepseek' \
--header 'Authorization: sk-' \
--header 'Content-Type: application/json' \
--header 'x-portkey-api-key: ' \
--data '{
        "model": "deepseek-chat",
        "messages": [
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "Tell me a story about love!"}
        ],
        "max_tokens": 100,
        "stream": false
}'

response

{
    "id": "85916956-abde-4b9a-99be-7d19a389a281",
    "object": "chat.completion",
    "created": 1737632471,
    "model": "deepseek-chat",
    "provider": "deepseek",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "Of course! Here's a story about love:\n\n---\n\n**The Garden of Two Hearts**\n\nOnce upon a time, in a quiet village nestled between rolling hills, there lived a young woman named Elara. She was known for her kindness and her love for flowers. Every morning, she would tend to her garden, where roses, lilies, and daisies bloomed in vibrant colors. The villagers often said her garden was the most beautiful in the land, but Elara felt something was missing"
            },
            "finish_reason": "length"
        }
    ],
    "usage": {
        "prompt_tokens": 16,
        "completion_tokens": 100,
        "total_tokens": 116
    }
}

@k99k5
Copy link
Author

k99k5 commented Jan 23, 2025

@narengogi curl --location 'https://api.portkey.ai/v1/chat/completions'
--header 'x-portkey-provider: deepseek'
--header 'x-portkey-config: xxxxxxxxxxx'
--header 'Content-Type: application/json'
--header 'x-portkey-api-key: xxxxxx'
--data '{
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me a story about game!"}
],
"max_tokens": 100,
"stream": true,
"stream_options": {"include_usage": true}
}'

@narengogi
Copy link
Collaborator

added the fix for this in
#897

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers triage
Projects
None yet
Development

No branches or pull requests

2 participants