Skip to content

feat(ai): add BytePlus/Volcengine Ark provider - #63481

Open
drpr wants to merge 2 commits into
anomalyco:devfrom
drpr:feat/ark-provider-core
Open

drpr wants to merge 2 commits into
anomalyco:devfrom
drpr:feat/ark-provider-core

Conversation

@drpr

@drpr drpr commented Nov 12, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #63480

Type of change

  • New feature

What does this PR do?

Add an Ark provider that extends openai-compatible with Volcengine-specific defaults.

  • Base URL: A single fallback URL (https://ark.cn-beijing.volces.com/api/v3). The model catalog's api.base_url wins over this default. BytePlus (overseas) users need to pass baseURL since their endpoint is https://ark.ap-southeast.bytepluses.com/api/v3.
  • thinking: An on/off switch ({ type: "enabled" | "disabled" }) for Ark's deep-reasoning mode, sent in the request body. This is not a budget — it controls whether deep reasoning is forced on or off. auto is documented but rejected by most models, so it is never sent.
  • reasoning_content: The streaming response field that carries the reasoning trace (set via compatibility.reasoningField).
  • promptCacheKey: true: Ark's implicit caching is automatic for supported models. The optional prompt_cache_key body field improves routing affinity for requests sharing the same prefix — it does not control whether caching is enabled. This is confirmed in the Ark context cache docs.
  • tools.strict: false: Ark does not support strict tool mode.
  • API key lookup: Checks ARK_API_KEY, BYTEPLUS_API_KEY, and ARK_CODING_PLAN_API_KEY.

Files: providers/ark.ts, providers/index.ts export, package.json subpath export, and construction/header tests.

How did you verify your code works?

  • bun turbo typecheck — 35/35 packages pass
  • bunx biome check — zero new warnings over dev baseline
  • Provider construction and header forwarding tests pass

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Public API: adds the @opencode/ai/providers/ark export and Ark provider namespace, reading ARK_API_KEY/BYTEPLUS_API_KEY/ARK_CODING_PLAN_API_KEY (backwards compatible)

Add an Ark provider that extends openai-compatible with Volcengine
defaults: region-based base URL, thinking budget, and prompt cache
key via the X-Ark-Prompt-Id header.

- providers/ark.ts: provider definition with Ark base URL and model list
- providers/index.ts: export the Ark provider
- package.json: export ./providers/ark subpath
- test/provider/ark.test.ts: construction and header forwarding tests

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The Ark route builds the expected Chat Completions request through model(). The added tests and a tsc type check pass, but I couldn't check it against a real Ark endpoint (no credentials). Two things in the code are worth fixing before merge; see the inline comments.

Public API: this adds the @opencode/ai/providers/ark subpath export, an Ark namespace in @opencode/ai/providers (id "ark", configure, provider, model, chat, route/routes, types Config/Settings/ChatOptionsInput), and API key lookup from ARK_API_KEY, BYTEPLUS_API_KEY and ARK_CODING_PLAN_API_KEY. All of it is new, so nothing existing breaks.

The description doesn't match the code:

  • There is one fixed cn-beijing base URL, not a region-based one, so BytePlus users get the wrong default endpoint unless they pass baseURL.
  • thinking is an on/off switch, not a budget.
  • Prompt caching sends the OpenAI body field prompt_cache_key. Nothing sends an X-Ark-Prompt-Id header.

Please update the description or the code so they match. As the split from #63471 intended, nothing in core uses this provider yet: it isn't registered in packages/core/src/provider.ts.

Comment thread packages/ai/src/providers/ark.ts Outdated
reasoningField: "reasoning_content",
maxTokensField: "max_tokens",
},
capabilities: { tools: { strict: false }, promptCacheKey: true },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

promptCacheKey: true makes the OpenAI Chat protocol put prompt_cache_key in the request body. I saw "prompt_cache_key":"sess1" in the compiled body. It doesn't send the X-Ark-Prompt-Id header described in the PR. Does Ark's /chat/completions accept prompt_cache_key? If Ark's caching is keyed by a header, it should be added as a header (like x-grok-conv-id in xai.ts) rather than enabling the body field.

chat() builds the model without the compatibility and capability settings that model() sets, so the two exported entry points behave differently. I compiled the same request through both: chat("m") sends max_completion_tokens instead of max_tokens, doesn't read reasoning_content from the stream, and leaves tools strict. Could both use one model factory, the way moonshot.ts does with model: chat, chat?

chat() was building the model without the compatibility and capabilities
settings that model() set, so the two entry points behaved differently:
chat() sent max_completion_tokens instead of max_tokens, did not read
reasoning_content from the stream, and left tools strict.

Share one factory function, the way moonshot.ts does with model: chat, chat.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Both earlier points are addressed. chat() and model() now share one factory, and I confirmed they compile the same request body with the same settings. Ark's current Chat API reference lists prompt_cache_key as a body field, so the prompt cache handling is fine. The Ark tests and tsc on packages/ai pass. I couldn't test against a real Ark endpoint (no credentials).

Public API: unchanged since the last review. The PR adds the @opencode/ai/providers/ark export and the Ark namespace, which is backwards compatible. Nothing new to flag.

This branch has not been deployed

No deployments
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.

feat: add BytePlus/Volcengine Ark provider support

1 participant