custom @ai-sdk/anthropic provider , context token usage display error #4524

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

Originally created by @caozhiyuan on GitHub (Jan 9, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Image

{"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":236,"output_tokens":81,"cache_read_input_tokens":12800}}

{
	"$schema": "https://opencode.ai/config.json",
	"model": "local/gpt-5.2-codex",
	"small_model": "local/gpt-5-mini",
	"agent": {
		"build": {
			"model": "local/gpt-5.2-codex"
		},
		"plan": {
			"model": "local/gpt-5.2-codex"
		},
		"explore": {
			"model": "local/gpt-5-mini"
		},
		"general": {
			"model": "local/gpt-5-mini"
		}
	},
	"mcp": {
		"fetch": {
			"type": "local",
			"command": ["uvx", "mcp-server-fetch", "--ignore-robots-txt"],
			"enabled": true
		}
	},
	"provider": {
		"local": {
			"npm": "@ai-sdk/anthropic",
			"name": "My Local",
			"options": {
				"baseURL": "http://localhost:4141/v1",
				"apiKey": "dummy"
			},
			"models": {
				"gpt-5.2-codex": {
					"name": "gpt-5.2-codex",
					"limit": {
						"context": 264000,
						"output": 64000
					}
				},
				"gpt-5-mini": {
					"name": "gpt-5-mini",
					"limit": {
						"context": 128000,
						"output": 64000
					}
				},
				"claude-sonnet-4.5": {
					"id": "claude-sonnet-4.5",
					"name": "claude-sonnet-4.5",
					"limit": {
						"context": 128000,
						"output": 16000
					},
					"options": {
						"thinking": {
							"type": "enabled",
							"budgetTokens": 15999
						}
					}
				}
			}
		}
	}
}

Plugins

No response

OpenCode version

1.1.8

Steps to reproduce

  1. ask hi
  2. see context info

Screenshot and/or share link

No response

Operating System

windows 11

Terminal

pwsh

Originally created by @caozhiyuan on GitHub (Jan 9, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description <img width="1366" height="606" alt="Image" src="https://github.com/user-attachments/assets/ebc860a4-9805-47ea-99be-1314c72d18eb" /> {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":236,"output_tokens":81,"cache_read_input_tokens":12800}} ``` { "$schema": "https://opencode.ai/config.json", "model": "local/gpt-5.2-codex", "small_model": "local/gpt-5-mini", "agent": { "build": { "model": "local/gpt-5.2-codex" }, "plan": { "model": "local/gpt-5.2-codex" }, "explore": { "model": "local/gpt-5-mini" }, "general": { "model": "local/gpt-5-mini" } }, "mcp": { "fetch": { "type": "local", "command": ["uvx", "mcp-server-fetch", "--ignore-robots-txt"], "enabled": true } }, "provider": { "local": { "npm": "@ai-sdk/anthropic", "name": "My Local", "options": { "baseURL": "http://localhost:4141/v1", "apiKey": "dummy" }, "models": { "gpt-5.2-codex": { "name": "gpt-5.2-codex", "limit": { "context": 264000, "output": 64000 } }, "gpt-5-mini": { "name": "gpt-5-mini", "limit": { "context": 128000, "output": 64000 } }, "claude-sonnet-4.5": { "id": "claude-sonnet-4.5", "name": "claude-sonnet-4.5", "limit": { "context": 128000, "output": 16000 }, "options": { "thinking": { "type": "enabled", "budgetTokens": 15999 } } } } } } } ``` ### Plugins _No response_ ### OpenCode version 1.1.8 ### Steps to reproduce 1. ask hi 2. see context info ### Screenshot and/or share link _No response_ ### Operating System windows 11 ### Terminal pwsh
yindo added the windowsbug labels 2026-02-16 17:44:28 -05:00
yindo closed this issue 2026-02-16 17:44:28 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 9, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #7025: Over 100% context usage - relates to context token display calculation errors
  • #5674: Custom OpenAI-compatible provider options not being passed to API calls - directly related to custom provider configuration issues with options like baseURL and apiKey
  • #6806: Partial thinking config doesn't merge with defaults - related to custom @ai-sdk/anthropic provider configuration with incomplete options
  • #7231: Anthropic team plan statistics don't show usage in OpenCode - relates to Anthropic provider usage and token reporting issues

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 9, 2026): This issue might be a duplicate of existing issues. Please check: - #7025: Over 100% context usage - relates to context token display calculation errors - #5674: Custom OpenAI-compatible provider options not being passed to API calls - directly related to custom provider configuration issues with options like baseURL and apiKey - #6806: Partial thinking config doesn't merge with defaults - related to custom @ai-sdk/anthropic provider configuration with incomplete options - #7231: Anthropic team plan statistics don't show usage in OpenCode - relates to Anthropic provider usage and token reporting issues Feel free to ignore if none of these address your specific case.
Author
Owner
@caozhiyuan commented on GitHub (Jan 10, 2026): seems https://github.com/vercel/ai/blob/ai%405.0.97/packages/anthropic/src/anthropic-messages-language-model.ts
Author
Owner

@caozhiyuan commented on GitHub (Jan 10, 2026):

@rekram1-node PR in https://github.com/anomalyco/opencode/pull/7643 , please help review.

@caozhiyuan commented on GitHub (Jan 10, 2026): @rekram1-node PR in https://github.com/anomalyco/opencode/pull/7643 , please help review.
Author
Owner

@caozhiyuan commented on GitHub (Jan 11, 2026):

@rekram1-node https://github.com/vercel/ai/blob/ai%405.0.97/packages/anthropic/src/anthropic-messages-language-model.ts#L1ai269
ai sdk anthropic set inputTokens and cachedInputTokens at message_start.
If inputTokens is 0, should taking from rawUsage at message_stop https://github.com/vercel/ai/blob/ai%405.0.97/packages/anthropic/src/anthropic-messages-language-model.ts#L1329.

@caozhiyuan commented on GitHub (Jan 11, 2026): @rekram1-node https://github.com/vercel/ai/blob/ai%405.0.97/packages/anthropic/src/anthropic-messages-language-model.ts#L1ai269 ai sdk anthropic set inputTokens and cachedInputTokens at message_start. If inputTokens is 0, should taking from rawUsage at message_stop https://github.com/vercel/ai/blob/ai%405.0.97/packages/anthropic/src/anthropic-messages-language-model.ts#L1329.
Author
Owner

@a1112 commented on GitHub (Jan 23, 2026):

It's my description that's problematic; all my shortcuts and mouse events turn into strange codes.

@a1112 commented on GitHub (Jan 23, 2026): It's my description that's problematic; all my shortcuts and mouse events turn into strange codes.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4524