abhigyanpatwari/GitNexus · error · Error

DeepSeek API key is required but was not provided

Error message

DeepSeek API key is required but was not provided

What it means

Thrown by createChatModel() in the 'deepseek' provider branch when deepseekConfig.apiKey is falsy or whitespace-only. DeepSeek is accessed through a DeepSeekChatOpenAI wrapper pointed at https://api.deepseek.com (hardcoded baseURL); the key is required at construction. Fails fast rather than letting the DeepSeek API return a 401 on first request.

Source

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

      return new ChatOpenAI({
        apiKey: glmConfig.apiKey,
        modelName: glmConfig.model,
        temperature: glmConfig.temperature ?? 0.1,
        maxTokens: glmConfig.maxTokens,
        configuration: {
          apiKey: glmConfig.apiKey,
          baseURL: glmConfig.baseUrl ?? 'https://api.z.ai/api/coding/paas/v4',
        },
        streaming: true,
      });
    }

    case 'deepseek': {
      const deepseekConfig = config as DeepSeekConfig;

      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}`);
  }

View on GitHub (pinned to d540b00184)

Solutions

  1. Obtain a key from platform.deepseek.com and enter it in provider settings
  2. Ensure the key is non-empty and non-whitespace
  3. Recreate the agent after setting the key (construction-time check)
  4. If you need a proxy/baseURL override, note DeepSeek's baseURL is hardcoded — use the openrouter or openai provider with a custom baseUrl instead

Example fix

// before
createChatModel({ provider: 'deepseek', apiKey: '', model: 'deepseek-chat' }); // throws

// after
createChatModel({ provider: 'deepseek', apiKey: userKey, model: 'deepseek-chat' });
Defensive patterns

Strategy: validation

Validate before calling

function hasDeepSeekKey(cfg: { apiKey?: string }): boolean {
  return typeof cfg.apiKey === 'string' && cfg.apiKey.trim().length > 0;
}
if (cfg.provider === 'deepseek' && !hasDeepSeekKey(cfg)) {
  throw new Error('Configure a DeepSeek API key (from platform.deepseek.com)');
}

Type guard

function isDeepSeekConfigReady(cfg: unknown): cfg is { provider: 'deepseek'; apiKey: string } {
  return typeof cfg === 'object' && cfg !== null
    && (cfg as any).provider === 'deepseek'
    && typeof (cfg as any).apiKey === 'string'
    && (cfg as any).apiKey.trim().length > 0;
}

Try / catch

try {
  createChatModel({ provider: 'deepseek', apiKey, model });
} catch (e) {
  if (e instanceof Error && /DeepSeek API key is required/.test(e.message)) {
    promptUserForKey('deepseek');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling createChatModel({ provider: 'deepseek', apiKey: undefined | '' | ' ', model: 'deepseek-chat', ... }). Note the baseURL is hardcoded to api.deepseek.com and cannot be overridden via config.

Common situations: The DeepSeek key wasn't set in provider settings; the env var is unset; switching to deepseek without a platform.deepseek.com account.

Related errors


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