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

Closed
opened 2026-02-16 17:28:12 -05:00 by yindo · 5 comments
Owner

Originally created by @kajdo on GitHub (Jul 16, 2025).

Originally assigned to: @thdxr on GitHub.

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
Originally created by @kajdo on GitHub (Jul 16, 2025). Originally assigned to: @thdxr on GitHub. 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 ```json "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%" <img width="835" height="54" alt="Image" src="https://github.com/user-attachments/assets/d0f38562-5da6-4b3a-98eb-472b82461d69" />
yindo closed this issue 2026-02-16 17:28:12 -05:00
Author
Owner

@onlyargon commented on GitHub (Jul 17, 2025):

moonshot with openrouter works by the way

@onlyargon commented on GitHub (Jul 17, 2025): moonshot with openrouter works by the way
Author
Owner

@kajdo commented on GitHub (Jul 17, 2025):

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

@kajdo commented on GitHub (Jul 17, 2025): > 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
Author
Owner

@hadikhantech commented on GitHub (Jul 23, 2025):

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)
@hadikhantech commented on GitHub (Jul 23, 2025): > 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)
Author
Owner

@jessevdp commented on GitHub (Jul 24, 2025):

This is a duplicate of https://github.com/sst/opencode/issues/423. It's a problem with providers that use @ai-sdk/openai-compatible.

@jessevdp commented on GitHub (Jul 24, 2025): This is a duplicate of https://github.com/sst/opencode/issues/423. It's a problem with providers that use `@ai-sdk/openai-compatible`.
Author
Owner

@rekram1-node commented on GitHub (Dec 27, 2025):

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

@rekram1-node commented on GitHub (Dec 27, 2025): [automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#763