ChatGPT 和 Gemini 是什么?它们是可以根据自然语言指令编写和解释代码的 AI 工具。向它们提供最新的 Neural4D 文本转 3D API 参考文档,帮助其编写用于创建模型的 Python 或 Node.js 脚本。API 快速入门介绍了身份验证和异步结果处理流程。使用任何生成的代码前,请先检查并测试。
你可以将此流程用于自定义 3D 应用、Discord 机器人或自动化内容流程。在将生成的资源用于成品前,请根据项目要求进行检查。
需要进行前端开发?如果你希望手动生成模型,并使用 Gemini 编写显示代码(例如 Three.js),请查看我们的 构建交互式 3D 网站指南。
需要直接集成代码?如果你是希望在不使用 AI 工具的情况下手动编写后端脚本的开发者,请查看我们的专门指南:如何将 Neural4D API 集成到自定义工作流程中。
运行脚本前,你需要一个用于 Bearer 身份验证的 API 密钥。有关详细操作步骤,请查看我们的指南:如何获取和管理 Neural4D API 密钥。
| 第 1 步 | 登录 Neural4D Studio。 |
| 第 2 步 | 点击左侧边栏底部的 API 图标。 |
| 第 3 步 | 点击 创建 API 密钥,然后为密钥输入标签。 |
| 第 4 步 | 点击 确认,然后妥善保存密钥。 |
请勿将密钥放入 AI 聊天、公共代码仓库或客户端代码中。下面的脚本会从本地环境变量中读取密钥。
向 AI 工具提供最新的 API 参考文档以及下面的请求流程。请按照原文复制此提示词。将真实 API 密钥保存在你的计算机上,绝不要粘贴到聊天中。
Write a Python script using requests to generate one 3D model with the Neural4D API.
Follow the current documentation:
https://docs.neural4d.com/en/api-reference/text-to-3d/generate-model-from-text
https://docs.neural4d.com/en/api-reference/model-management/retrieve-model
1. Read the API key from the NEURAL4D_API_KEY environment variable. If it is missing, show a clear error. Never print or hard-code the key.
2. Build the Authorization header as Bearer plus the key read from NEURAL4D_API_KEY. Send POST https://alb.neural4d.com:3000/api/generateModelWithText with Content-Type: application/json. Use JSON: {"prompt": "A futuristic sci-fi helmet", "modelCount": 1}.
3. Check the HTTP response and API errors. Save the first UUID from the response's "uuids" array.
4. Poll POST https://alb.neural4d.com:3000/api/retrieveModel with JSON {"uuid": saved_uuid} and the same headers. Use a configurable interval and a maximum wait time.
5. In the retrieval response, "codeStatus" 1 means generating and 0 means complete. Handle -1 (invalid or expired token), -2 (unknown UUID), and -3 (generation failed) as errors.
6. When complete, download the asset from "modelUrl" and preserve its file extension when available. Do not assume the result is an OBJ file.
7. Add request timeouts, helpful error messages, and comments explaining how to run the script.运行生成的脚本前,请根据链接的 API 页面检查脚本内容。如果需要 OBJ 文件,请在生成模型后使用单独的模型格式转换 API。格式转换会消耗点数。
ChatGPT 或 Gemini 提供 Python 脚本后,请先检查脚本,然后按照以下步骤操作:
pip install requests 安装 requests 库。NEURAL4D_API_KEY 设置为你的 API 密钥。在 PowerShell 中,使用
$env:NEURAL4D_API_KEY="your_key"。在命令提示符中,使用 set NEURAL4D_API_KEY=your_key。在
macOS 或 Linux 中,使用 export NEURAL4D_API_KEY="your_key"。
python generate_3d.py。脚本会持续查询任务,直到任务完成、失败或达到配置的超时时间。请求失败时,请检查 HTTP 响应和 API 响应正文:
| 401 或 codeStatus -1 | 检查是否已设置 NEURAL4D_API_KEY,以及密钥是否有效。如果旧密钥已过期或被撤销,请生成新密钥。 |
| 400 Bad Request | 根据当前的文本转 3D 参考文档检查 JSON 字段名称和值。 |
| 402 或 403 | 检查账户余额、权限以及任何账户限制。 |
| 429 Too Many Requests | 请先等待一段时间再重试,并降低脚本发送请求的频率。 |
| 审核响应 | 生成请求可能会返回审核消息,而不是 uuids 数组。请阅读该消息并修改提示词。 |
| codeStatus -2 或 -3 | 确认 UUID 来自创建响应。值为 -2 表示未找到;-3 表示生成失败。 |
| ModuleNotFoundError | 使用 pip install requests 安装 Python requests 库。
|
| 脚本超时 | 任务可能仍在运行。请检查 任务进度接口,或尝试设置更长的最长等待时间后重试。不要假定任务会在固定时间内完成。 |