Skip to content

Named custom providers ignore api_mode, always create OpenAI client #9711

@fuyizheng3120

Description

@fuyizheng3120

Description

resolve_provider_client() in agent/auxiliary_client.py handles named custom providers (from custom_providers list in config.yaml) by unconditionally creating an OpenAI(...) client, even when the provider's api_mode is anthropic_messages.

# Line ~1460 in v0.9.0
client = OpenAI(api_key=custom_key, base_url=custom_base)

This means custom providers pointing to Anthropic-compatible endpoints (corporate proxies, self-hosted deployments) send requests in OpenAI format, causing ChatCompletion.choices = None crashes.

Context

This is the third layer of the bug reported in #8857. PR #8871 (merged in v0.9.0) correctly fixed:

  1. _normalize_aux_provider() stripping named provider identity for vision tasks
  2. resolve_vision_provider_client() not propagating api_mode downstream

But the underlying issue remains: even with api_mode correctly propagated, the named custom provider code path never checks it.

Expected Behavior

When a named custom provider has api_mode: anthropic_messages (either in config or passed as parameter), resolve_provider_client() should create an AnthropicAuxiliaryClient wrapping the native Anthropic SDK — mirroring how _try_anthropic() already handles the built-in anthropic provider.

Suggested Fix

In the named custom provider block of resolve_provider_client():

effective_api_mode = api_mode or custom_entry.get("api_mode", "")
if effective_api_mode == "anthropic_messages":
    try:
        from agent.anthropic_adapter import build_anthropic_client
        real_client = build_anthropic_client(custom_key, custom_base)
        client = AnthropicAuxiliaryClient(
            real_client, final_model, custom_key, custom_base)
    except ImportError:
        logger.warning(
            "resolve_provider_client: anthropic SDK not available "
            "for custom provider %r, falling back to OpenAI client",
            provider)
        client = OpenAI(api_key=custom_key, base_url=custom_base)
else:
    client = OpenAI(api_key=custom_key, base_url=custom_base)

Environment

  • Hermes v0.9.0 (v2026.4.13), macOS
  • Custom provider: corporate Anthropic proxy with api_mode: anthropic_messages
  • Patched locally and working in production

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existsarea/configConfig system, migrations, profilescomp/agentCore agent loop, run_agent.py, prompt buildersweeper:implemented-on-mainSweeper: behavior already present on current maintype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions