Back to Home

Image Describer API 文档

2025-02-22

Posted by

Image Describer API 文档

简介及用例

Image Describer API 允许您将 AI 驱动的图像描述功能集成到您的应用程序中。我们的 API 使用先进的 AI 模型来分析图像并生成详细的描述。

常见用例

  • 为图像生成详细的描述
  • 从图像中提取文本和信息
  • 分析图像内容和上下文
  • 为创意写作创建角色描述
  • 为内容管理生成图像标题

API 密钥

要使用我们的 API,您需要获取 API 凭据(API 密钥和密钥)。您可以在控制台中管理您的 API 密钥。

管理 API 密钥 →

API 端点

POST https://imagedescriber.online/api/openapi/describe-image

集成指南

请求头

Header NameRequiredDescription
content-type必须是 multipart/form-data
appid您从控制台获取的 API 密钥
timestamp当前时间戳,以毫秒为单位
nonce随机 UUID 字符串,用于请求唯一性,必须是唯一的,并且长度在 6 到 32 个字符之间。例如,4dc6gvrjg1
signature用于身份验证的 HMAC-SHA256 签名(参见代码示例

请求参数

ParameterTypeRequiredDescription
imageBase64Datastring带有 MIME 类型前缀的 Base64 编码图像数据(例如,data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE...
promptstring用于图像分析的自定义提示
langstring响应语言 (en/zh/de/es/fr/ja/ko)

响应格式

FieldTypeDescription
codenumber响应状态码。200 表示成功
dataobject响应数据对象,当 code 为 200 时出现
data.contentstring生成的图像描述
msgstring响应消息,提供附加信息
succeedboolean指示请求是否成功

示例响应

{
    "code": 200,
    "data": {
        "content": "图像的详细描述,采用 markdown 格式..."
    },
    "succeed": true,
    "msg": "成功"
}

错误代码

CodeMessageDescription
200OK请求成功
500SERVER_ERROR服务器内部错误
10003INSUFFICIENT_CREDITS积分不足
10004INVALID_PARAM参数无效
10005HARMFUL_CONTENT检测到有害内容
30001INVALID_API_KEYAPI 密钥无效
30002INVALID_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 调用会消耗您帐户中的积分。您可以在我们的定价页面上购买积分。

查看定价 →

帮助与支持

如果您有任何问题或需要帮助,请随时联系我们的支持团队。

邮箱:[email protected]