Skip to content

[Upstream PR #94] Add anthropic-compatible provider type and custom headers #83

@quangdang46

Description

@quangdang46

Mirrored from upstream 1jehuang/jcodePull Request #94 by @namphamdev
Original state: open
Created: 2026-05-02T02:40:13Z · Updated: 2026-05-02T02:41:32Z
Diff: https://github.com/1jehuang/jcode/pull/94.diff
This issue is an auto-mirrored copy. Comments and edits here are local to quangdang46/jcode — do not expect them to propagate upstream.


Summary

  • Adds a new \NamedProviderType::AnthropicCompatible\ variant (TOML aliases anthropic-compatible\ / anthropic_compatible) so users can register named profiles that target Anthropic Messages-API gateways.
  • Adds a per-profile \headers\ map (\BTreeMap<String, String>) on \NamedProviderConfig\ and wires it through the OpenRouter/OpenAI-compatible runtime so the configured headers are attached to every chat-completion POST.
  • Extends \jcode provider add\ with two new flags:
    • --type <openai-compatible|anthropic-compatible>\
    • --header KEY=VALUE\ (repeatable, also accepts \KEY:VALUE)
  • Validates header names (ASCII letters/digits/-/_), rejects CR/LF in values, and refuses reserved hop-by-hop names at runtime.
  • Persists the chosen type and [providers..headers]\ table to \config.toml; --overwrite\ cleanup now also recognizes the headers subsection.

Files

  • \crates/jcode-config-types/src/lib.rs\ - new enum variant + \headers\ field
  • \src/cli/args.rs\ / \src/cli/dispatch.rs\ / \src/cli/commands/provider_setup.rs\ - new flags, parsing, TOML emission, tests
  • \src/provider/openrouter.rs\ - \parse_named_provider_extra_headers\ + reserved-name guard, struct field, ctor wiring
  • \src/provider/openrouter_provider_impl.rs\ / \openrouter_sse_stream.rs\ - thread \extra_headers\ into the request path
  • \src/provider/openrouter_tests.rs\ - update test fixtures for the new field

Tests

  • \parse_custom_header_args_accepts_kv_and_rejects_invalid\
  • \provider_add_writes_anthropic_compatible_type_with_custom_headers\
  • \cargo check\ and \cargo check --tests\ are clean for these changes (unrelated pre-existing
    easoning_effort\ errors in \src/overnight.rs\ exist on master too).

Example

\
$ jcode provider add my-claude-gw \
--type anthropic-compatible \
--base-url https://gateway.example.com/v1 \
--model claude-sonnet-4 \
--header anthropic-beta=beta1,beta2 \
--header X-Org=acme \
--api-key-stdin
\\


View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions