> ## Documentation Index
> Fetch the complete documentation index at: https://docs.geekai.co/llms.txt
> Use this file to discover all available pages before exploring further.

# 首次调用API

## 快速开始

第三方应用可以通过 API 接口调用极客智坊聚合的所有 AI 模型，目前开放了 AI 模型代理、AI 搜索、文件对话和 OCR 服务，后续会逐步开放更多 AI 服务接口。

极客智坊 API 使用与 OpenAI 兼容的 API 格式，通过修改配置，您可以使用 OpenAI SDK 来访问极客智坊 API，或使用与 OpenAI API 兼容的软件（第三方应用接入）：

<div style={{ width: '100%', overflowX: 'auto' }}>
  <table style={{ width: '100%', borderCollapse: 'collapse', tableLayout: 'fixed' }}>
    <thead>
      <tr>
        <th style={{ border: '1px solid #ccc', padding: '10px', }}>参数</th>
        <th style={{ border: '1px solid #ccc', padding: '10px',width: '80%' }}>值</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>Base URL</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          国内版调用入口： `https://geekai.co/api/v1` <br />
          海外版调用入口： `https://geekai.dev/api/v1`
        </td>
      </tr>

      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>API KEY</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          国内版 API KEY：<a href="https://geekai.co/user/api_keys" target="_blank">[https://geekai.co/user/api\_keys](https://geekai.co/user/api_keys)</a> <br />
          海外版 API KEY：<a href="https://geekai.dev/user/api_keys" target="_blank">[https://geekai.dev/user/api\_keys](https://geekai.dev/user/api_keys)</a> <br />
          API KEY 与代理渠道关联，不同渠道对应不同折扣值，可通过编辑 API KEY 切换。
        </td>
      </tr>
    </tbody>
  </table>
</div>

<Note>
  极客智坊所有对话模型均兼容 OpenAI，包括 Claude、Gemini 在内，因此在 AI 对话模型场景，请使用 OpenAI 兼容模式创建供应商，执行 AI 模型代理时，将官方 BaseURL 和 API KEY 替换成极客智坊的 Base URL 和 API KEY 即可。
</Note>

<Note>
  有时候 Base URL 不能带 `/v1` 后缀，尤其是在一些第三方应用中，此时需要根据实际情况调整 Base URL，如果带 `/v1` 后缀报错，不妨试试将其去掉。
</Note>

<Note>
  调用 API 请自觉遵守国内法律法规，不要做危害国家安全的事情，如遇敏感词报错，请将 API 入口切换到 `https://geekai.dev`，需要注意的是，**国内版和国外版账号数据不通**，需要分别注册账号以及创建对应的 API KEY。
</Note>

在创建&复制 API key 之后，你可以使用以下示例代码访问极客智坊 API。示例为非流式输出，您可以将 `stream` 设置为 `true` 来使用流式输出：

<CodeGroup>
  ```bash curl theme={null}
  curl https://geekai.co/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GEEKAI_API_KEY" \
  -d '{
      "model": "gpt-5-mini",
      "messages": [
          {"role": "system", "content": "你是一个智能助理"},
          {"role": "user", "content": "你好"}
      ],
      "stream": false
  }'
  ```

  ```bash python theme={null}
  # 先安装 OpenAI SDK: `pip3 install openai`

  from openai import OpenAI

  client = OpenAI(api_key="$GEEKAI_API_KEY", base_url="https://geekai.co/api/v1")

  response = client.chat.completions.create(
      model="gpt-5-mini",
      messages=[
          {"role": "system", "content": "你是一个智能助理"},
          {"role": "user", "content": "你好"},
      ],
      stream=False
  )

  print(response.choices[0].message.content)
  ```

  ```bash javascript theme={null}
  // 先安装 OpenAI SDK: `npm install openai`

  import OpenAI from "openai";

  const openai = new OpenAI({
      baseURL: 'https://geekai.co/api/v1',
      apiKey: '$GEEKAI_API_KEY'
  });

  async function main() {
      const completion = await openai.chat.completions.create({
          messages: [
            { role: "system", content: "你是一个智能助理" },
            { role: "user", content: "你好" }],
          model: "gpt-5-mini",
      });

      console.log(completion.choices[0].message.content);
  }

  main();
  ```

  ```bash go theme={null}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"fmt"
  	"io"
  	"net/http"
  )

  func main() {
  	requestBody := map[string]interface{}{
  		"model": "gpt-5-mini",
  		"messages": []interface{}{
        map[string]interface{}{
          "role": "system", 
          "content": "你是一个智能助理",
        },
        map[string]interface{}{
          "role": "user", 
          "content": "你好",
        },
      }
  	}
  	
  	jsonData, err := json.Marshal(requestBody)
  	if err != nil {
  		panic(err)
  	}

  	client := &http.Client{}
  	req, err := http.NewRequest("POST", "https://geekai.co/api/v1/chat/completions", bytes.NewBuffer(jsonData))
  	if err != nil {
  		panic(err)
  	}

  	req.Header.Set("Authorization", "Bearer $GEEKAI_API_KEY")
  	req.Header.Set("Content-Type", "application/json")

  	resp, err := client.Do(req)
  	if err != nil {
  		panic(err)
  	}
  	defer resp.Body.Close()

  	body, err := io.ReadAll(resp.Body)
  	if err != nil {
  		panic(err)
  	}

  	fmt.Println(string(body))
  }
  ```
</CodeGroup>

流式输出的原理是 SSE（Server-Sent Events），当启用流式输出后，客户端代码需要适配流式输出，以前端代码为例，需要通过 `EventSource` 从服务端接收流式响应， 否则会报错。

## 图片分析

如果你想要分析图片，可以使用以下示例代码：

<CodeGroup>
  ```bash curl theme={null}
  curl https://geekai.co/api/v1/chat/completions   
    -H "Content-Type: application/json"
    -H "Authorization: Bearer $GEEKAI_API_KEY"   
    -d '{
      "model": "gpt-5-mini",
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "text",
              "text": "图片包含什么内容?"
            },
            {
              "type": "image_url",
              "image_url": {
                "url": "https://static.geekai.co/logo/geekai-logo-main-tr.png"
              }
            }
          ]
        }
      ]
    }'
  ```

  ```bash python theme={null}
  from openai import OpenAI

  client = OpenAI(api_key="$GEEKAI_API_KEY", base_url="https://geekai.co/api/v1")

  response = client.chat.completions.create(
      model="gpt-5-mini",
      messages=[
          {
              "role": "user",
              "content": [
                  {"type": "text", "text": "图片包含什么内容?"},
                  {
                      "type": "image_url",
                      "image_url": {
                          "url": "https://static.geekai.co/logo/geekai-logo-main-tr.png",
                      },
                  },
              ],
          }
      ]
  )

  print(response.choices[0].message.content)
  ```

  ```bash javascript theme={null}
  import OpenAI from "openai";

  const openai = new OpenAI({
      baseURL: 'https://geekai.co/api/v1',
      apiKey: '$GEEKAI_API_KEY'
  });

  const response = await openai.chat.completions.create({
      model: "gpt-5-mini",
      messages: [
          {
              role: "user",
              content: [
                  { type: "text", text: "图片包含什么内容?" },
                  {
                      type: "image_url",
                      image_url: {
                          url: "https://static.geekai.co/logo/geekai-logo-main-tr.png",
                      },
                  },
              ],
          },
      ],
  });

  console.log(response.choices[0].message.content);
  ```

  ```bash go theme={null}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"fmt"
  	"io"
  	"net/http"
  )

  func main() {
  	requestBody := map[string]interface{}{
  		"model": "gpt-5-mini",
  		"messages": []interface{}{
        map[string]interface{}{
          "role": "user", 
          "content": []interface{}{
            map[string]interface{}{
              "type": "text", 
              "text": "图片包含什么内容?",
            },
            map[string]interface{}{
              "type": "image_url", 
              "image_url": map[string]interface{}{
                "url": "https://static.geekai.co/logo/geekai-logo-main-tr.png",
              },
            },
          },
        },
      }
  	}
  	
  	jsonData, err := json.Marshal(requestBody)
  	if err != nil {
  		panic(err)
  	}

  	client := &http.Client{}
  	req, err := http.NewRequest("POST", "https://geekai.co/api/v1/chat/completions", bytes.NewBuffer(jsonData))
  	if err != nil {
  		panic(err)
  	}

  	req.Header.Set("Authorization", "Bearer $GEEKAI_API_KEY")
  	req.Header.Set("Content-Type", "application/json")

  	resp, err := client.Do(req)
  	if err != nil {
  		panic(err)
  	}
  	defer resp.Body.Close()

  	body, err := io.ReadAll(resp.Body)
  	if err != nil {
  		panic(err)
  	}

  	fmt.Println(string(body))
  }
  ```
</CodeGroup>

只有支持图片识别的多模态模型才支持图片识别和分析，你可以在[模型广场](https://geekai.co/models)查看所有支持图片识别的模型。

## 开发者群

调用过程中有任何问题，可以加入开发者群咨询，我们会第一时间为您解答：

<img src="https://static.geekai.co/image/geekai_wechat_group.png" className="mt-2" alt="极客智坊微信群" />

你可以在群里获悉极客智坊最新动态、技术分享、产品功能、API 使用等信息。
