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

# 创建 3D 模型

> 创建一个 3D 模型生成任务

使用 Tripo3D 和其他提供商从文本或图像生成 3D 模型。这是一个异步 API。

公开 3D operation 会从请求形状推导：仅包含 `prompt` 的请求解析为 `text-to-3d`，带 `image` 或 `image_url` 的请求解析为 `image-to-3d`。此 endpoint 不暴露 `operation` 请求字段；不要发送旧的 `3d-generation` 值。

## 请求体

<ParamField body="model" type="string" default="tripo-h3.1">
  要使用的模型，例如 `tripo-h3.1` 或 `tripo-p1.0`。依赖某个输入类型或输出格式前，请先查询 `GET /v1/models?recommended_for=3d`。
</ParamField>

<ParamField body="prompt" type="string" required>
  要生成的 3D 模型的文本描述。
</ParamField>

<ParamField body="image" type="string">
  用于图像转 3D 生成的 Base64 编码图像。
</ParamField>

<ParamField body="image_url" type="string">
  用于图像转 3D 生成的图像 URL。
</ParamField>

<ParamField body="format" type="string" default="glb">
  输出格式：`glb`、`fbx`、`obj` 或 `usdz`。
</ParamField>

<ParamField body="quality" type="string" default="standard">
  质量等级：`draft`、`standard` 或 `high`。
</ParamField>

<ParamField body="style" type="string">
  模型的风格预设。
</ParamField>

<ParamField body="seed" type="integer">
  用于可复现生成的种子。
</ParamField>

<ParamField body="user" type="string">
  终端用户的唯一标识符。
</ParamField>

## 响应

<ResponseField name="id" type="string">
  用于轮询状态的任务 ID。
</ResponseField>

<ResponseField name="status" type="string">
  任务状态：`pending`、`processing`、`completed` 或 `failed`。
</ResponseField>

<ResponseField name="created" type="integer">
  任务创建的 Unix 时间戳。
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.tokenlab.sh/v1/3d/generations" \
    -H "Authorization: Bearer sk-your-api-key" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "tripo-h3.1",
      "prompt": "A detailed medieval castle with towers",
      "format": "glb",
      "quality": "high"
    }'
  ```

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

  response = requests.post(
      "https://api.tokenlab.sh/v1/3d/generations",
      headers={"Authorization": "Bearer sk-your-api-key"},
      json={
          "model": "tripo-h3.1",
          "prompt": "A detailed medieval castle with towers",
          "format": "glb",
          "quality": "high"
      }
  )

  task_id = response.json()["id"]
  print(f"Task ID: {task_id}")
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.tokenlab.sh/v1/3d/generations', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer sk-your-api-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      model: 'tripo-h3.1',
      prompt: 'A detailed medieval castle with towers',
      format: 'glb',
      quality: 'high'
    })
  });

  const data = await response.json();
  console.log(`Task ID: ${data.id}`);
  ```

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

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

  func main() {
      payload := map[string]interface{}{
          "model":   "tripo-h3.1",
          "prompt":  "A detailed medieval castle with towers",
          "format":  "glb",
          "quality": "high",
      }
      body, _ := json.Marshal(payload)

      req, _ := http.NewRequest("POST", "https://api.tokenlab.sh/v1/3d/generations", bytes.NewBuffer(body))
      req.Header.Set("Authorization", "Bearer sk-your-api-key")
      req.Header.Set("Content-Type", "application/json")

      client := &http.Client{}
      resp, _ := client.Do(req)
      defer resp.Body.Close()

      var result map[string]interface{}
      json.NewDecoder(resp.Body).Decode(&result)
      fmt.Printf("Task ID: %s\n", result["id"])
  }
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://api.tokenlab.sh/v1/3d/generations');

  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_HTTPHEADER => [
          'Content-Type: application/json',
          'Authorization: Bearer sk-your-api-key'
      ],
      CURLOPT_POSTFIELDS => json_encode([
          'model' => 'tripo-h3.1',
          'prompt' => 'A detailed medieval castle with towers',
          'format' => 'glb',
          'quality' => 'high'
      ])
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  $data = json_decode($response, true);
  echo "Task ID: " . $data['id'];
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    "status": "pending",
    "created": 1706000000,
    "model": "tripo-h3.1"
  }
  ```
</ResponseExample>
