abhigyanpatwari/GitNexus · error · Error

Unsupported provider: ${(config as any).provider}

Error message

Unsupported provider: ${(config as any).provider}

What it means

Thrown by createChatModel() in the default switch arm when config.provider does not match any supported provider. Supported values are: openai, azure-openai, gemini, anthropic, ollama, openrouter, minimax, glm, deepseek (see LLMProvider type). The offending value is echoed in the message to aid diagnosis. This is a type-safety backstop — TypeScript would normally prevent it, but runtime config from user input/storage can carry an unknown value.

Source

Thrown at gitnexus-web/src/core/llm/agent.ts:348

      if (!deepseekConfig.apiKey || deepseekConfig.apiKey.trim() === '') {
        throw new Error('DeepSeek API key is required but was not provided');
      }

      return new DeepSeekChatOpenAI({
        apiKey: deepseekConfig.apiKey,
        modelName: deepseekConfig.model,
        temperature: deepseekConfig.temperature ?? 0.1,
        maxTokens: deepseekConfig.maxTokens,
        configuration: {
          apiKey: deepseekConfig.apiKey,
          baseURL: 'https://api.deepseek.com',
        },
        streaming: true,
      });
    }

    default:
      throw new Error(`Unsupported provider: ${(config as any).provider}`);
  }
};

/**
 * Extract instance name from Azure endpoint URL
 * e.g., "https://my-resource.openai.azure.com" -> "my-resource"
 */
const extractInstanceName = (endpoint: string): string => {
  try {
    const url = new URL(endpoint);
    const hostname = url.hostname;
    // Extract the first part before .openai.azure.com. The trailing `$`
    // anchor is required (CodeQL js/regex/missing-regexp-anchor): without
    // it `evil.openai.azure.com.attacker.tld` would match.
    const match = hostname.match(/^([^.]+)\.openai\.azure\.com$/);
    if (match) {
      return match[1];
    }

View on GitHub (pinned to d540b00184)

Solutions

  1. Set config.provider to one of: openai, azure-openai, gemini, anthropic, ollama, openrouter, minimax, glm, deepseek
  2. Check for typos — common ones: 'claude'→'anthropic', 'azure'→'azure-openai', 'gpt'→'openai'
  3. Clear persisted provider settings and re-select from the UI if a version skew corrupted the stored value
  4. If adding a new provider, add a case arm to the switch in createChatModel and extend the LLMProvider type

Example fix

// before — wrong provider id
createChatModel({ provider: 'claude', apiKey: 'k', model: 'x' }); // throws

// after — correct id
createChatModel({ provider: 'anthropic', apiKey: 'k', model: 'claude-3-5-sonnet-20241022' });
Defensive patterns

Strategy: type-guard

Validate before calling

import type { LLMProvider } from '../core/llm/types.js';
const SUPPORTED: readonly LLMProvider[] = ['openai','azure-openai','gemini','anthropic','ollama','openrouter','minimax','glm','deepseek'];
function isSupportedProvider(p: string): p is LLMProvider {
  return (SUPPORTED as readonly string[]).includes(p);
}
if (!isSupportedProvider(cfg.provider)) {
  throw new Error(`Unknown provider '${cfg.provider}'. Supported: ${SUPPORTED.join(', ')}`);
}

Type guard

import type { LLMProvider } from '../core/llm/types.js';
function isLLMProvider(p: unknown): p is LLMProvider {
  return typeof p === 'string' && ['openai','azure-openai','gemini','anthropic','ollama','openrouter','minimax','glm','deepseek'].includes(p);
}

Try / catch

try {
  createChatModel(cfg);
} catch (e) {
  if (e instanceof Error && /Unsupported provider/.test(e.message)) {
    // show user the supported list, default to a working provider
    cfg.provider = 'ollama';
    return createChatModel(cfg);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling createChatModel with a provider string outside the supported union, e.g. 'claude' (should be 'anthropic'), 'gpt' (should be 'openai'), 'azure' (should be 'azure-openai'), or a typo. Common when persisted settings from an older or newer version are loaded.

Common situations: A settings migration gap where a renamed provider id persists in localStorage; user-edited config with a typo; a frontend version skew between the persisted settings shape and the current provider list.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12). Data as JSON: /api/errors/818346d1438b5c9b. Report an issue: GitHub.