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 聊天內容、公開儲存庫或用戶端程式碼中。下方腳本會從本機環境變數讀取金鑰。
將目前的 API 參考文件與下方的請求流程提供給 AI 工具。請依照原文複製此提示詞。請將真正的 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 函式庫。
|
| 指令碼逾時 | 工作可能仍在執行中。請查看 工作進度端點,或改用較長的最長等待時間重新嘗試。不要假設固定的完成時間。 |