Skip to content

token count not working for some providers (moonshot.ai for example) #1071

Closed

Description

@kajdo

i added moonshot.ai directly in configuration.json and it works fine, but the counter and the cost is not calculated at runtime of opencode

"moonshot_ai_direct": {
	"npm": "@ai-sdk/openai-compatible",
	"name": "Moonshot AI (Direct)",
	"options": {
		"baseURL": "https://api.moonshot.ai/v1",
		"apiKey": "sk-sadöfjsdklöfjaösdlkjfasdköjfködfjdjfa"
	},
	"models": {
		"kimi-k2-0711-preview": {
			"name": "Kimi K2 (Direct)",
			"cost": { "input": 0.6, "output": 2.5, "cache_read": 0.15 },
			"limit": { "context": 131072, "output": 131072 }
		}
	}
}

the token count is always showing "0/0%"

Image

Activity

  1. onlyargon commented on Jul 17, 2025

    @onlyargon

    moonshot with openrouter works by the way

  2. kajdo commented on Jul 17, 2025

    @kajdo
    Author

    moonshot with openrouter works by the way

    yes, but due to different providers - the toolcalls work or don't (issues already exist). I changed to moonshot.ai to give it a try if the toolcalls work consistantly (which i can confirm).

    the token count is just a minor thing - but it would be nice if it works, since 132k context size is reached mid "working" if i forget to /compact

  3. self-assigned this
    on Jul 17, 2025
  4. hadikhantech commented on Jul 23, 2025

    @hadikhantech

    moonshot with openrouter works by the way

    It's not the same as directly from moonshot.

    • No prompt caching
    • Many providers use a quantised version and do not support tool calls (openrouter routes to them)
  5. jessevdp commented on Jul 24, 2025

    @jessevdp
    Contributor

    This is a duplicate of #423. It's a problem with providers that use @ai-sdk/openai-compatible.

  6. rekram1-node commented on Dec 28, 2025

    @rekram1-node
    Collaborator

    [automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions