> ## 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.

# 图像生成

你可以通过 OpenAI 内置的画图工具 `image_generation` 实现在对话中生成图像的功能，以下是图像生成的请求示例：

<CodeGroup>
  ```bash curl theme={null}
  curl --location --request POST 'https://geekai.co/api/v1/responses' \
  --header 'Authorization: Bearer {YOUR_GEEKAI_API_KEY}' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      "model": "gpt-5",
      "input": "画一只可爱的小猫",
      "tools": [
          {
              "type": "image_generation"
          }
      ]
  }'
  ```

  ```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.responses.create(
      model="gpt-5",
      input="画一只可爱的小猫",
      tools=[
          {
              "type": "image_generation"
          }
      ]
  )
  print(response)
  ```

  ```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 response = await openai.responses.create({
          model: "gpt-5",
          input: "画一只可爱的小猫",
          tools: [
              {
                  "type": "image_generation"
              }
          ]
      });
      console.log(response);
  }
  main();
  ```

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

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

  func main() {
  	requestBody := map[string]any{
  		"model": "gpt-5",
  		"input": "画一只可爱的小猫",
  		"tools": []any{
  			map[string]any{
  				"type": "image_generation"
  			},
  		},
  	}

  	jsonData, err := json.Marshal(requestBody)
  	if err != nil {
  		panic(err)
  	}

  	client := &http.Client{}
  	req, err := http.NewRequest("POST", "https://geekai.co/api/v1/responses", 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>

图像生成工具支持以下模型：

* `gpt-5`
* `gpt-5-nano`
* `gpt-4.1`
* `gpt-4.1-mini`
* `gpt-4.1-nano`
* `gpt-4o`
* `gpt-4o-mini`
* `o3`

图像生成过程始终使用 `gpt-image-1` 模型，所以会按照该模型生成图像费用收费，且支持 `gpt-image-1` 模型的所有参数：

<CodeGroup>
  ```bash curl theme={null}
  curl --location --request POST 'https://geekai.co/api/v1/responses' \
  --header 'Authorization: Bearer {YOUR_GEEKAI_API_KEY}' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      "model": "gpt-4.1",
      "input": "画一只可爱的小猫",
      "tools": [
          {
              "type": "image_generation"，
              "background": "transparent",
              "quality": "high"
          }
      ]
  }'
  ```
</CodeGroup>

不同尺寸不同质量图片收费倍率和官方一致。
