Image Describer API 文档
2025-02-22
Posted byImage Describer API 文档
简介及用例
Image Describer API 允许您将 AI 驱动的图像描述功能集成到您的应用程序中。我们的 API 使用先进的 AI 模型来分析图像并生成详细的描述。
常见用例
- 为图像生成详细的描述
- 从图像中提取文本和信息
- 分析图像内容和上下文
- 为创意写作创建角色描述
- 为内容管理生成图像标题
API 密钥
要使用我们的 API,您需要获取 API 凭据(API 密钥和密钥)。您可以在控制台中管理您的 API 密钥。
API 端点
POST https://imagedescriber.online/api/openapi/describe-image
集成指南
请求头
Header Name | Required | Description |
---|---|---|
content-type | 是 | 必须是 multipart/form-data |
appid | 是 | 您从控制台获取的 API 密钥 |
timestamp | 是 | 当前时间戳,以毫秒为单位 |
nonce | 是 | 随机 UUID 字符串,用于请求唯一性,必须是唯一的,并且长度在 6 到 32 个字符之间。例如,4dc6gvrjg1 |
signature | 是 | 用于身份验证的 HMAC-SHA256 签名(参见代码示例) |
请求参数
Parameter | Type | Required | Description |
---|---|---|---|
imageBase64Data | string | 是 | 带有 MIME 类型前缀的 Base64 编码图像数据(例如,data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE... ) |
prompt | string | 否 | 用于图像分析的自定义提示 |
lang | string | 否 | 响应语言 (en/zh/de/es/fr/ja/ko) |
响应格式
Field | Type | Description |
---|---|---|
code | number | 响应状态码。200 表示成功 |
data | object | 响应数据对象,当 code 为 200 时出现 |
data.content | string | 生成的图像描述 |
msg | string | 响应消息,提供附加信息 |
succeed | boolean | 指示请求是否成功 |
示例响应
{
"code": 200,
"data": {
"content": "图像的详细描述,采用 markdown 格式..."
},
"succeed": true,
"msg": "成功"
}
错误代码
Code | Message | Description |
---|---|---|
200 | OK | 请求成功 |
500 | SERVER_ERROR | 服务器内部错误 |
10003 | INSUFFICIENT_CREDITS | 积分不足 |
10004 | INVALID_PARAM | 参数无效 |
10005 | HARMFUL_CONTENT | 检测到有害内容 |
30001 | INVALID_API_KEY | API 密钥无效 |
30002 | INVALID_SIGNATURE | 请求签名无效 |
代码示例
Next.js 示例
import fs from 'fs';
// Get image base64 data: Server-side implementation
const buffer = await fs.readFileSync("/temp/test.jpg");
const base64Image = buffer.toString('base64');
const imageBase64Data = `data:image/jpeg;base64,${base64Image}`;
// Get image base64 data: Client-side implementation
const file:File = /* file from input or drop event */;
const arrayBuffer = await file.arrayBuffer();
const bytes = new Uint8Array(arrayBuffer);
const base64Image = btoa(String.fromCharCode.apply(null, bytes as any));
const imageBase64Data = `data:${file.type};base64,${base64Image}`;
// Request Body
const formData = new FormData();
formData.append('imageBase64Data', imageBase64Data);
formData.append('lang', 'en');
formData.append('prompt', 'Summarize the content of the picture in one sentence, then describe in detail what is in the picture, including objects, people, animals, and the atmosphere and mood of the picture');
// Signature
const appid = "app_1234567";
const secret = "sk_a8f3dbb3...";
const timestamp = Date.now().toString();
const nonce = crypto.randomBytes(4).toString('hex');
const signStr = buildSignString(appid, timestamp, nonce); // See subsequent code for function implementation
const sign = await sign(signStr, secret); // See subsequent code for function implementation
// Do Request
const response = await fetch('https://imagedescriber.online/api/openapi/describe-image', {
method: 'POST',
headers: {
'appid': appid,
'timestamp': timestamp,
'nonce': nonce,
'signature': sign
},
body: formData
});
const result = await response.json();
console.log(result);
function buildSignString(appId: string, timestamp: string, nonce: string): string {
return [appId, timestamp, nonce].join('-');
}
async function sign(message: string, secret: string): Promise<string> {
const encoder = new TextEncoder();
const keyData = encoder.encode(secret);
const messageData = encoder.encode(message);
const key = await crypto.subtle.importKey(
'raw',
keyData,
{ name: 'HMAC', hash: 'SHA-256' },
false,
['sign']
);
const signatureData = await crypto.subtle.sign(
'HMAC',
key,
messageData
);
return btoa(String.fromCharCode.apply(null, Array.from(new Uint8Array(signatureData))));
}
定价
API 调用会消耗您帐户中的积分。您可以在我们的定价页面上购买积分。
帮助与支持
如果您有任何问题或需要帮助,请随时联系我们的支持团队。