Skip to content

[Bug] Token usage not working when using MoonshotAI official API #6614

@Soulter

Description

@Soulter

What happened / 发生了什么

MoonshotAI official API does not use standard OpenAI API in token usage.

Received chunk: ChatCompletionChunk(id='chatcmpl-69bbcc292af1bf47c1d8a74b', choices=[Choice(delta=ChoiceDelta(content=' name', function_call=None, refusal=None, role=None, tool_calls=None), finish_reason=None, index=0, logprobs=None)], created=1773915177, model='kimi-k2-0905-preview', object='chat.completion.chunk', service_tier=None, system_fingerprint='fpv0_e76aa377', usage=None)
Received chunk: ChatCompletionChunk(id='chatcmpl-69bbcc292af1bf47c1d8a74b', choices=[Choice(delta=ChoiceDelta(content='?', function_call=None, refusal=None, role=None, tool_calls=None), finish_reason=None, index=0, logprobs=None)], created=1773915177, model='kimi-k2-0905-preview', object='chat.completion.chunk', service_tier=None, system_fingerprint='fpv0_e76aa377', usage=None)
Received chunk: ChatCompletionChunk(id='chatcmpl-69bbcc292af1bf47c1d8a74b', choices=[Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None), finish_reason='stop', index=0, logprobs=None, usage={'prompt_tokens': 1336, 'completion_tokens': 31, 'total_tokens': 1367, 'cached_tokens': 1280, 'prompt_tokens_details': {'cached_tokens': 1280}})], created=1773915177, model='kimi-k2-0905-preview', object='chat.completion.chunk', service_tier=None, system_fingerprint='fpv0_e76aa377', usage=None)

Reproduce / 如何复现?

Using MoonshotAI API(official)

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

OS

Linux

Logs / 报错日志

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions