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

# 生成图片

> 通过文本提示词生成图片，并可选上传参考图。单次请求最多可上传 6 张参考图，并提交 1 到 4 个生成任务。

## 授权

<ParamField header="Authorization" type="string" required default={'Bearer ${YOUR_API_KEY}'}>
  使用 Neural4D 网站提供的 Bearer token。
</ParamField>

## 请求体 <span className="api-content-type">multipart/form-data</span>

<ParamField body="prompt" type="string" required>
  描述目标图片内容的文本提示词。
</ParamField>

<ParamField body="images" type="string<binary>[]">
  用于引导生成的可选参考图。

  数组长度：`0 - 6` 个元素。
</ParamField>

<ParamField body="modelKey" type="enum<string>" default="image-2">
  图片生成模型标识。

  可选值：`image-2`、`nano_banana_pro`。
</ParamField>

<ParamField body="aspectRatio" type="enum<string>" default="1:1">
  生成图片的目标宽高比。

  可选值：`1:1`、`16:9`、`9:16`、`4:3`、`3:4`。
</ParamField>

<ParamField body="jobNum" type="integer" default={1}>
  提交的生成任务数量。

  取值范围：`1 <= x <= 4`。
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://alb.neural4d.com:3000/api/createNormalPicture \
    --header 'Authorization: Bearer <token>' \
    --form 'prompt=a beautiful flower' \
    --form 'images=@/path/to/file' \
    --form 'images=@/path/to/file' \
    --form 'images=@/path/to/file' \
    --form 'jobNum=2' \
    --form 'modelKey=image-2' \
    --form 'aspectRatio=4:3'
  ```

  ```python Python theme={null}
  import requests

  response = requests.request(
      "POST",
      "https://alb.neural4d.com:3000/api/createNormalPicture",
      headers={
      "Authorization": "Bearer <token>",
      },
      files={"images": open('/path/to/file', 'rb'), "images": open('/path/to/file', 'rb'), "images": open('/path/to/file', 'rb')},
  )
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://alb.neural4d.com:3000/api/createNormalPicture", {
    method: "POST",
    headers: {
      "Authorization": "Bearer <token>"
    },
    body: (() => { const form = new FormData(); form.append("file", fileInput.files[0]); return form; })(),
  });
  const data = await response.json();
  console.log(data);
  ```

  ```typescript TypeScript theme={null}
  const response: Response = await fetch("https://alb.neural4d.com:3000/api/createNormalPicture", {
    method: "POST",
    headers: {
      "Authorization": "Bearer <token>"
    },
    body: (() => { const form = new FormData(); form.append("file", fileInput.files[0]); return form; })(),
  });
  const data = await response.json();
  console.log(data);
  ```

  ```java Java theme={null}
  import java.net.URI;
  import java.net.http.*;

  HttpRequest request = HttpRequest.newBuilder()
      .uri(URI.create("https://alb.neural4d.com:3000/api/createNormalPicture"))
      .header("Authorization", "Bearer <token>")
      .method("POST", HttpRequest.BodyPublishers.noBody())
      .build();
  HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
  System.out.println(response.body());
  ```

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

  import (
    "fmt"
    "io"
    "net/http"
    "strings"
  )

  payload := nil
  req, _ := http.NewRequest("POST", "https://alb.neural4d.com:3000/api/createNormalPicture", payload)
  req.Header.Set("Authorization", "Bearer <token>")
  resp, _ := http.DefaultClient.Do(req)
  defer resp.Body.Close()
  bodyBytes, _ := io.ReadAll(resp.Body)
  fmt.Println(string(bodyBytes))
  ```

  ```ruby Ruby theme={null}
  require "net/http"
  require "json"

  uri = URI("https://alb.neural4d.com:3000/api/createNormalPicture")
  request = Net::HTTP::Post.new(uri)
  request["Authorization"] = "Bearer <token>"

  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
  puts response.body
  ```

  ```php PHP theme={null}
  <?php

  $ch = curl_init("https://alb.neural4d.com:3000/api/createNormalPicture");
  curl_setopt_array($ch, [
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_HTTPHEADER => ["Authorization: Bearer <token>"],
  ]);
  $response = curl_exec($ch);
  curl_close($ch);
  echo $response;
  ```

  ```csharp C# theme={null}
  using System.Net.Http;
  using System.Text;

  using var client = new HttpClient();
  using var request = new HttpRequestMessage(HttpMethod.Post, "https://alb.neural4d.com:3000/api/createNormalPicture");
  request.Headers.TryAddWithoutValidation("Authorization", "Bearer <token>");
  using var response = await client.SendAsync(request);
  Console.WriteLine(await response.Content.ReadAsStringAsync());
  ```
</RequestExample>

## 响应

<Tabs sync={false}>
  <Tab title="200">
    已接受图片生成任务

    <ResponseField name="success" type="boolean" required>
      生成请求是否已被接受。
    </ResponseField>

    <ResponseField name="data" type="object" required>
      已接受生成请求的队列和任务详情。

      <Expandable title="child attributes">
        <ResponseField name="pointsDeducted" pre={["data."]} type="integer" required>
          当前已接受生成请求扣除的点数。
        </ResponseField>

        <ResponseField name="queueStatus" pre={["data."]} type="string" required>
          已提交任务的当前排队状态。
        </ResponseField>

        <ResponseField name="jobNum" pre={["data."]} type="integer" required>
          已接受的生成任务数量。
        </ResponseField>

        <ResponseField name="uuids" pre={["data."]} type="string[]" required>
          分配给每个已接受生成任务的 UUID。
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Tab>
</Tabs>

<ResponseExample>
  ```json 200 queued theme={null}
  {
    "success": true,
    "data": {
      "pointsDeducted": 26,
      "queueStatus": "queued",
      "jobNum": 2,
      "uuids": [
        "834d7e8c-bd70-48d8-9830-ca1ad9886e33",
        "774bd78d-d14f-4531-8972-321086c92edu"
      ]
    }
  }
  ```
</ResponseExample>
