File size: 2,182 Bytes
6886758
568b90c
 
 
 
 
6886758
 
568b90c
6886758
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
export function getProviderConfig(provider, model) {
  // Check for both OPENCLAW_API_KEY and provider-specific keys
  const apiKey = process.env.OPENCLAW_API_KEY || 
                 process.env.DEEPSEEK_API_KEY || 
                 process.env.OPENAI_API_KEY ||
                 process.env.ANTHROPIC_API_KEY;

  if (!apiKey) {
    throw new Error("API key not set. Set OPENCLAW_API_KEY, DEEPSEEK_API_KEY, or provider-specific key");
  }

  switch (provider) {
    case "openai":
      return {
        name: "openai",
        baseUrl: "https://api.openai.com/v1/chat/completions",
        model: model || "gpt-4.1-mini",
        headers: {
          "Authorization": `Bearer ${apiKey}`,
          "Content-Type": "application/json"
        }
      };

    case "deepseek":
      return {
        name: "deepseek",
        baseUrl: "https://api.deepseek.com/chat/completions",
        model: model || "deepseek-chat",
        headers: {
          "Authorization": `Bearer ${apiKey}`,
          "Content-Type": "application/json"
        }
      };

    case "gemini":
      return {
        name: "gemini",
        baseUrl: `https://generativelanguage.googleapis.com/v1beta/models/${model || "gemini-1.5-pro"}:generateContent?key=${apiKey}`,
        model,
        headers: {
          "Content-Type": "application/json"
        }
      };

    case "openrouter":
      return {
        name: "openrouter",
        baseUrl: "https://openrouter.ai/api/v1/chat/completions",
        model: model || "openai/gpt-4o-mini",
        headers: {
          "Authorization": `Bearer ${apiKey}`,
          "Content-Type": "application/json",
          "HTTP-Referer": "https://getzero11-openclaw.hf.space",
          "X-Title": "OpenClaw Market Research Agent"
        }
      };

    case "dashscope":
      return {
        name: "dashscope",
        baseUrl: "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation",
        model: model || "qwen-plus",
        headers: {
          "Authorization": `Bearer ${apiKey}`,
          "Content-Type": "application/json"
        }
      };

    default:
      throw new Error(`Unsupported provider: ${provider}`);
  }
}