魔法提示词
1. 接口地址
https://www.hidreamai.com/api-pub/gw/v3/text/magic_prompt/sync
2. 请求方式
POST
3. 请求参数
Header
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
Authorization | string | 是 | 客户授权Token |
Content-Type | string | 是 | 使用json传参 |
API-User-ID | string | 否 | 用户唯一标识 |
Body
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
prompt | string | 是 | 提示词 |
model | string | 是 | txt2img, txt2video, img2img, img2video |
version | string | 否 | 模型版本,默认为"v1",可选范围为{"v1"} |
request_id | string | 否 | 请求的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. 返回参数
参数 | 类型 | 说明 |
---|---|---|
code | int | 返回状态码 |
message | string | 返回状态信息 |
request_id | string | 本次请求的ID |
result | dict | 返回结果 |
其中返回结果 result
字段具体为:
参数 | 类型 | 说明 |
---|---|---|
prompt | string | 返回的魔法提示词 |
示例:
{
"code": 0,
"message": "Success",
"request_id": "d2b60ad6-1453-11f0-a229-6eb78049809b",
"result": {
"prompt": "小丑鱼在五彩斑斓的珊瑚礁中穿梭,阳光透过清澈的海水洒下,形成斑驳的光影。珊瑚礁生机勃勃,各种热带鱼围绕着小丑鱼游动。温暖的阳光和生动的色彩营造出一种欢快而宁静的氛围。风格偏向自然写实。"
}
}