Skip to content

fix: use custom api type to prevent conflict with built-in Anthropic provider#1

Open
ramonvg wants to merge 1 commit into
Leechael:mainfrom
ramonvg:fix/custom-api-type-prevent-anthropic-conflict
Open

fix: use custom api type to prevent conflict with built-in Anthropic provider#1
ramonvg wants to merge 1 commit into
Leechael:mainfrom
ramonvg:fix/custom-api-type-prevent-anthropic-conflict

Conversation

@ramonvg
Copy link
Copy Markdown

@ramonvg ramonvg commented Apr 20, 2026

Problem

When KIMI_CODE_PROTOCOL is not set (the default), the provider registers with api: "anthropic-messages" — the same built-in API type used by the Anthropic provider. Combined with a custom streamSimple, this causes pi-coding-agent to route Claude/Anthropic requests through streamSimpleKimi, resulting in:

Error: 401 {"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}

The official custom-provider-anthropic example shows the correct pattern: when using streamSimple, always register with a custom api string (e.g. "custom-anthropic-api"), not a built-in one.

Changes

  1. Add KIMI_API_TYPE — resolves to "kimi-anthropic-messages" or "kimi-openai-completions" instead of the built-in names.

  2. Change api: PROTOCOLapi: KIMI_API_TYPE in registerProvider — the root fix; the kimi provider no longer claims a built-in protocol handler.

  3. Route by PROTOCOL instead of model.api in streamSimpleKimi — since model.api is now a custom string, the OpenAI vs Anthropic branch uses the module-level PROTOCOL constant instead.

  4. Guard apiKey forwarding in buildPatchedOptions — never spread an empty apiKey onto patchedOptions, which would silently overwrite a valid OAuth credential passed in by the caller.


Summary by cubic

Prevents conflicts with the built-in Anthropic provider by registering kimi-coding with custom API types, so Claude/Anthropic requests no longer route through streamSimpleKimi and return 401s. Also improves credential handling and internal routing.

  • Bug Fixes
    • Register with custom api values: kimi-anthropic-messages / kimi-openai-completions (via KIMI_API_TYPE).
    • Route upstream by PROTOCOL instead of model.api to align with the custom api.
    • Forward apiKey only when present to avoid overwriting caller OAuth credentials.

Written for commit 489fd3c. Summary will update on new commits.

…provider

Register kimi-coding with kimi-anthropic-messages / kimi-openai-completions
instead of the built-in anthropic-messages / openai-completions api types.
Using a built-in api type with a custom streamSimple caused pi-coding-agent
to route Claude/Anthropic requests through streamSimpleKimi, resulting in
a 401 invalid x-api-key error.

Also guard apiKey forwarding in buildPatchedOptions so an empty/missing
KIMI_API_KEY never overwrites the caller's OAuth credential, and route
internally by PROTOCOL instead of model.api since the registered api type
is now a custom string.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@LeonardoRick
Copy link
Copy Markdown

LeonardoRick commented Apr 23, 2026

+1, Thanks for the fix! This is affecting me right now as I'm trying to toggle Kimi <-> Claude after installing this extension.

image

Could we get it merged?

@LeonardoRick
Copy link
Copy Markdown

Hello @Leechael! Any change to get this merged?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants