文档
魔法提示词接口

魔法提示词

1. 接口地址

https://www.hidreamai.com/api-pub/gw/v3/text/magic_prompt/sync

 

2. 请求方式

POST

 

3. 请求参数

Header

参数类型是否必填说明
Authorizationstring客户授权Token
Content-Typestring使用json传参
API-User-IDstring用户唯一标识

Body

参数类型是否必填说明
promptstring提示词
modelstringtxt2img, txt2video, img2img, img2video
versionstring模型版本,默认为"v1",可选范围为{"v1"}
request_idstring请求的ID,默认为""

curl示例

curl -H 'Authorization: Bearer {USER_Authorization}' -H 'Content-Type: application/json' -X POST -d '{
    "prompt": "小丑鱼",
    "model": "txt2img",
    "version": "v1",
    "request_id": "c1b18500-f3cc-11ed-aa62-5bbc7ccc3f99",
}' -v 'https://www.hidreamai.com/api-pub/gw/v3/text/magic_prompt/sync'

Python示例

import requests
import json
import uuid
 
USER_Authorization = <token>
 
 
# 请求头
headers = {
    'Authorization': f'Bearer {USER_Authorization}',
    'Content-Type': 'application/json',
    'API-User-ID': ''  # 可选的用户唯一标识
}
 
# 请求体参数
data = {
    "prompt": "小丑鱼",
    "model": "txt2img",
    "version": "v1",
    "request_id": "c1b18500-f3cc-11ed-aa62-5bbc7ccc3f99",
}
 
# 发送POST请求
url = 'https://www.hidreamai.com/api-pub/gw/v3/text/magic_prompt/sync'
response = requests.post(url, headers=headers, data=json.dumps(data))
 
# 处理响应
if response.status_code == 200:
    if response.json()['code'] == 0:
        magic_prompt = response.json()['result']['prompt']
        print(magic_prompt)
    else:
        print(response.json()['message'])
else:
    print(response.status_code)

 

4. 返回参数

参数类型说明
codeint返回状态码
messagestring返回状态信息
request_idstring本次请求的ID
resultdict返回结果

其中返回结果 result字段具体为:

参数类型说明
promptstring返回的魔法提示词

示例:

{
    "code": 0,
    "message": "Success",
    "request_id": "d2b60ad6-1453-11f0-a229-6eb78049809b",
    "result": {
        "prompt": "小丑鱼在五彩斑斓的珊瑚礁中穿梭,阳光透过清澈的海水洒下,形成斑驳的光影。珊瑚礁生机勃勃,各种热带鱼围绕着小丑鱼游动。温暖的阳光和生动的色彩营造出一种欢快而宁静的氛围。风格偏向自然写实。"
    }
}