https://api.neural4d.com/openapi/v1。以下通过文生 3D 演示核心调用流程。各语言示例均从环境变量 YOUR_API_KEY 读取密钥。
1. 配置 API 密钥
使用有效付费订阅账户,在 API Key 页面 获取密钥。配置 API 密钥
export YOUR_API_KEY='替换为你的 API 密钥'
2. 创建 3D 生成任务
提交提示词,生成带 PBR 材质的 3D 模型。需要同时设置with_texture: true 和 with_pbr: true。每次请求都通过 Authorization: Bearer 携带密钥。
curl --request POST \
--url "https://api.neural4d.com/openapi/v1/3dmodels/generations" \
--header "Authorization: Bearer ${YOUR_API_KEY}" \
--header 'Content-Type: application/json' \
--data '{
"model": "dreamtech/neural4d-2.5",
"prompt": "白色摄影棚背景中的陶瓷茶壶",
"with_texture": true,
"with_pbr": true
}'
import os
import requests
api_key = os.environ["YOUR_API_KEY"]
response = requests.post(
"https://api.neural4d.com/openapi/v1/3dmodels/generations",
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
},
json={
"model": "dreamtech/neural4d-2.5",
"prompt": "白色摄影棚背景中的陶瓷茶壶",
"with_texture": True,
"with_pbr": True,
},
)
print(response.json())
const apiKey = process.env.YOUR_API_KEY;
const response = await fetch(
"https://api.neural4d.com/openapi/v1/3dmodels/generations",
{
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "dreamtech/neural4d-2.5",
prompt: "白色摄影棚背景中的陶瓷茶壶",
with_texture: true,
with_pbr: true,
}),
}
);
console.log(await response.json());
const apiKey = process.env.YOUR_API_KEY;
const response: Response = await fetch(
"https://api.neural4d.com/openapi/v1/3dmodels/generations",
{
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "dreamtech/neural4d-2.5",
prompt: "白色摄影棚背景中的陶瓷茶壶",
with_texture: true,
with_pbr: true,
}),
}
);
console.log(await response.json());
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
class Main {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("YOUR_API_KEY");
String payload = String.join("\n",
"{",
" \"model\": \"dreamtech/neural4d-2.5\",",
" \"prompt\": \"白色摄影棚背景中的陶瓷茶壶\",",
" \"with_texture\": true,",
" \"with_pbr\": true",
"}"
);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.neural4d.com/openapi/v1/3dmodels/generations"))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(
request,
HttpResponse.BodyHandlers.ofString()
);
System.out.println(response.body());
}
}
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"strings"
)
func main() {
apiKey := os.Getenv("YOUR_API_KEY")
payload := strings.NewReader(`{
"model": "dreamtech/neural4d-2.5",
"prompt": "白色摄影棚背景中的陶瓷茶壶",
"with_texture": true,
"with_pbr": true
}`)
request, err := http.NewRequest(
"POST",
"https://api.neural4d.com/openapi/v1/3dmodels/generations",
payload,
)
if err != nil {
log.Fatal(err)
}
request.Header.Set("Authorization", "Bearer "+apiKey)
request.Header.Set("Content-Type", "application/json")
response, err := http.DefaultClient.Do(request)
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
body, err := io.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
require "net/http"
require "json"
api_key = ENV.fetch("YOUR_API_KEY")
uri = URI("https://api.neural4d.com/openapi/v1/3dmodels/generations")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{api_key}"
request["Content-Type"] = "application/json"
request.body = {
"model": "dreamtech/neural4d-2.5",
"prompt": "白色摄影棚背景中的陶瓷茶壶",
"with_texture": true,
"with_pbr": true
}.to_json
response = Net::HTTP.start(
uri.hostname,
uri.port,
use_ssl: uri.scheme == "https"
) do |http|
http.request(request)
end
puts response.body
<?php
$apiKey = getenv('YOUR_API_KEY');
$payload = <<<'JSON'
{
"model": "dreamtech/neural4d-2.5",
"prompt": "白色摄影棚背景中的陶瓷茶壶",
"with_texture": true,
"with_pbr": true
}
JSON;
$ch = curl_init("https://api.neural4d.com/openapi/v1/3dmodels/generations");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . $apiKey,
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => $payload,
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
using System;
using System.Net.Http;
using System.Text;
var apiKey = Environment.GetEnvironmentVariable("YOUR_API_KEY");
var payload = @"{
""model"": ""dreamtech/neural4d-2.5"",
""prompt"": ""白色摄影棚背景中的陶瓷茶壶"",
""with_texture"": true,
""with_pbr"": true
}";
using var client = new HttpClient();
using var request = new HttpRequestMessage(
HttpMethod.Post,
"https://api.neural4d.com/openapi/v1/3dmodels/generations"
);
request.Headers.TryAddWithoutValidation(
"Authorization",
"Bearer " + apiKey
);
request.Content = new StringContent(
payload,
Encoding.UTF8,
"application/json"
);
using var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
202 Accepted。保存任务 id,用于后续查询。以下响应为结构示例,ID、资源地址和 usage.credits 以实际返回为准。
202 已接受
{
"id": "normal-3d-c50fe63e-699d-4d61-93f5-2099ab159d6d",
"status": "queued",
"created_at": 1784044800,
"mode": "text_to_3d",
"model": "dreamtech/neural4d-2.5",
"data": [
{
"uuid": "72e30159-a242-4491-a67c-2ad0cfc9efb6",
"status": "queued",
"created_at": 1784044800
}
],
"usage": {
"credits": 30
}
}
3. 查询并下载结果
将下面的id 替换为创建任务返回的值,间隔数秒查询一次。queued 和 processing 表示尚未完成;succeeded 表示成功,failed 表示失败,此时查看响应中的 error。
curl --request GET \
--url "https://api.neural4d.com/openapi/v1/tasks/task-info?id=normal-3d-c50fe63e-699d-4d61-93f5-2099ab159d6d" \
--header "Authorization: Bearer ${YOUR_API_KEY}"
import os
import requests
api_key = os.environ["YOUR_API_KEY"]
response = requests.get(
"https://api.neural4d.com/openapi/v1/tasks/task-info?id=normal-3d-c50fe63e-699d-4d61-93f5-2099ab159d6d",
headers={
"Authorization": f"Bearer {api_key}",
},
)
print(response.json())
const apiKey = process.env.YOUR_API_KEY;
const response = await fetch(
"https://api.neural4d.com/openapi/v1/tasks/task-info?id=normal-3d-c50fe63e-699d-4d61-93f5-2099ab159d6d",
{
method: "GET",
headers: {
Authorization: `Bearer ${apiKey}`,
},
}
);
console.log(await response.json());
const apiKey = process.env.YOUR_API_KEY;
const response: Response = await fetch(
"https://api.neural4d.com/openapi/v1/tasks/task-info?id=normal-3d-c50fe63e-699d-4d61-93f5-2099ab159d6d",
{
method: "GET",
headers: {
Authorization: `Bearer ${apiKey}`,
},
}
);
console.log(await response.json());
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
class Main {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("YOUR_API_KEY");
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.neural4d.com/openapi/v1/tasks/task-info?id=normal-3d-c50fe63e-699d-4d61-93f5-2099ab159d6d"))
.header("Authorization", "Bearer " + apiKey)
.GET()
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(
request,
HttpResponse.BodyHandlers.ofString()
);
System.out.println(response.body());
}
}
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
)
func main() {
apiKey := os.Getenv("YOUR_API_KEY")
request, err := http.NewRequest(
"GET",
"https://api.neural4d.com/openapi/v1/tasks/task-info?id=normal-3d-c50fe63e-699d-4d61-93f5-2099ab159d6d",
nil,
)
if err != nil {
log.Fatal(err)
}
request.Header.Set("Authorization", "Bearer "+apiKey)
response, err := http.DefaultClient.Do(request)
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
body, err := io.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
require "net/http"
api_key = ENV.fetch("YOUR_API_KEY")
uri = URI("https://api.neural4d.com/openapi/v1/tasks/task-info?id=normal-3d-c50fe63e-699d-4d61-93f5-2099ab159d6d")
request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Bearer #{api_key}"
response = Net::HTTP.start(
uri.hostname,
uri.port,
use_ssl: uri.scheme == "https"
) do |http|
http.request(request)
end
puts response.body
<?php
$apiKey = getenv('YOUR_API_KEY');
$ch = curl_init("https://api.neural4d.com/openapi/v1/tasks/task-info?id=normal-3d-c50fe63e-699d-4d61-93f5-2099ab159d6d");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . $apiKey,
],
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
using System;
using System.Net.Http;
var apiKey = Environment.GetEnvironmentVariable("YOUR_API_KEY");
using var client = new HttpClient();
using var request = new HttpRequestMessage(
HttpMethod.Get,
"https://api.neural4d.com/openapi/v1/tasks/task-info?id=normal-3d-c50fe63e-699d-4d61-93f5-2099ab159d6d"
);
request.Headers.TryAddWithoutValidation(
"Authorization",
"Bearer " + apiKey
);
using var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
200 成功
{
"id": "normal-3d-c50fe63e-699d-4d61-93f5-2099ab159d6d",
"status": "succeeded",
"model": "dreamtech/neural4d-2.5",
"created_at": 1784044800,
"updated_at": 1784044842,
"mode": "text_to_3d",
"output": {
"models": [
{
"uuid": "72e30159-a242-4491-a67c-2ad0cfc9efb6",
"format": "glb",
"model_urls": {
"glb": "https://s3.neural4d.com/results/model.glb"
},
"thumbnail_urls": {
"front": "https://s3.neural4d.com/results/t1.png"
},
"mesh_quality": "standard",
"pose": "auto",
"target_polycount": 500000,
"topology": "triangle",
"with_texture": true,
"with_pbr": true,
"image_enhancement": false,
"mode": "text_to_3d",
"status": "succeeded",
"created_at": 1784044800,
"updated_at": 1784044842
}
]
},
"usage": {
"credits": 30
}
}
model_urls.glb 下载模型,thumbnail_urls.front 查看缩略图;未生成时 thumbnail_urls 为 {}。
本示例生成三角面 GLB,PBR 材质和贴图随 GLB 加载。
更多用法:3D 生成参数 · 完整任务响应 · 上传参考文件。