AI 图像标签 API 是一项强大的 AI 照片标记服务,可自动为图像生成智能标签、标题和描述。该 自动图像标记 API 利用先进的计算机视觉和机器学习技术来分析图像内容,并提供全面的元数据生成。它非常适用于自动图像标记、内容管理和智能照片分类等工作流程。
AI 图像标签 API 使您能够在以下领域高效地实现 AI 照片标记和元数据生成:
要访问 AI 图像标签 API,您必须首先获取一个有效的 API 密钥。该密钥用于验证您的请求,并确保对 API 的安全访问。
重要提示: 请勿与他人分享密钥,或将其暴露在浏览器、客户端代码或任何其他不安全的位置。请妥善保管您的密钥,以防未经授权的访问。
POST https://api.imagedescriber.app/api/v1/generate_tags
Header | 类型 | 必需 | 描述 |
---|---|---|---|
content-type | string | 是 | `application/json` |
authorization | string | 是 | `Bearer ${api_key}`,其中 `${api_key}` 是您的 API 密钥。 |
自动图像标记 API 接受以下请求结构:
{
"image": "data:image/jpeg;base64,{image_base64_data}",
"lang": "zh"
}
参数 | 类型 | 必需 | 描述 |
---|---|---|---|
image | string | 是 | 图像的 Base64 编码数据。支持的图像格式请参见 图像格式详情。 |
lang | string | 否 | 返回的标签和描述的语言代码。默认为 `en` (英语)。支持的语言代码列表如下。 |
代码 | 语言 |
---|---|
en | 英语 (默认) |
zh | 中文 |
fr | 法语 |
de | 德语 |
es | 西班牙语 |
ja | 日语 |
ko | 韩语 |
curl --location 'https://api.imagedescriber.app/api/v1/generate_tags' \
--header 'content-type: application/json' \
--header 'authorization: Bearer 您的_API_密钥' \
--data '{
"image":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE...",
"lang":"zh"
}'
import requests
import base64
def image_to_base64(image_path):
"""将图像转换为 Base64 编码"""
with open(image_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
return encoded_string
def generate_image_tags(api_key, image_path, lang="zh"):
"""使用 AI 图像标签 API 生成 AI 图像标签"""
url = "https://api.imagedescriber.app/api/v1/generate_tags"
headers = {
"content-type": "application/json",
"authorization": f"Bearer {api_key}"
}
image_base64_data = image_to_base64(image_path)
payload = {
"image": f"data:image/jpeg;base64,{image_base64_data}",
"lang": lang
}
response = requests.post(url, headers=headers, json=payload)
if response.status_code == 200:
result = response.json()
tags_data = result["data"]["tags"]
print("生成的标签:", tags_data["tags"])
print("标题:", tags_data["title"])
print("描述:", tags_data["description"])
print("剩余积分:", result["data"]["credits"]["remaining"])
else:
print(f"错误: {response.status_code}")
print(response.text)
# 使用示例
api_key = "您的_API_密钥"
image_path = "您的_图像.jpg"
generate_image_tags(api_key, image_path)
import fs from 'fs';
// 服务端实现
const buffer = await fs.readFileSync("/temp/test.jpg");
const base64Image = buffer.toString('base64');
const imageData = `data:image/jpeg;base64,${base64Image}`;
// 客户端实现
const file: File = /* 来自 input 或拖放事件的文件 */;
const arrayBuffer = await file.arrayBuffer();
const bytes = new Uint8Array(arrayBuffer);
const base64Image = btoa(String.fromCharCode.apply(null, bytes as any));
const imageData = `data:${file.type};base64,${base64Image}`;
const body = {
"image": imageData,
"lang": "zh"
};
const response = await fetch('https://api.imagedescriber.app/api/v1/generate_tags', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {您的_API_密钥}'
},
body: JSON.stringify(body),
});
const result = await response.json();
console.log('AI 生成的标签:', result.data.tags.tags);
console.log('生成的标题:', result.data.tags.title);
console.log('生成的描述:', result.data.tags.description);
AI 图片标记服务会返回一个包含生成的标签、标题、描述和积分信息的完整响应:
{
"code": 0,
"message": "success",
"request_id": "唯一的请求ID字符串",
"data": {
"tags": {
"tags": [
"标签1",
"标签2",
...
],
"title": "简单且吸引人的图像标题",
"description": "详细的图像描述"
},
"credits": {
"amount": "本次调用消耗的积分",
"remaining": "本次调用后剩余的总积分"
}
}
}
字段 | 类型 | 描述 |
---|---|---|
code | number | 状态码,`0` 表示成功,非 `0` 表示错误。 |
message | string | 状态消息,描述请求的状态。 |
request_id | string | 唯一的请求 ID,用于跟踪和问题排查。 |
data | object | 包含生成的标签数据和点数信息。 |
tags | object | 包含 AI 生成的图像标签、标题和描述。 |
tags.tags | array | 为图像生成的 AI 照片标签数组。 |
tags.title | string | 总结图像内容的 AI 生成标题。 |
tags.description | string | 关于图像内容和背景的详细描述。 |
credits | object | 关于积分消耗和剩余余额的信息。 |
credits.amount | number | 本次 API 调用消耗的积分。 |
credits.remaining | number | 本次调用后您账户中剩余的总积分。 |
为确保服务的稳定性和公平性,每个 API 密钥的请求频率限制为每分钟 30 次请求(每小时 1800 次请求)。超过此限制的请求将被拒绝,并返回错误码 1004
。
如何获取更多积分?
您可以访问 积分充值页面 购买积分套餐,以支持更多的 AI 图片标记 API 调用。我们提供多种套餐,以满足不同用户的需求。
下表列出了常见的错误码、其含义及解决方案:
错误码 | 描述 | 解决方案 |
---|---|---|
1002 | 未经授权 | 请验证您的 `authorization` 请求头是否设置正确。 |
1003 | API 密钥无效 | 请验证您的 API 密钥是否正确,或获取一个新的密钥。 |
1004 | 请求过于频繁 | 请降低您的请求频率,最大为每分钟 30 次。 |
1005 | 参数无效 | 请验证您的请求参数是否符合规范。 |
2002 | 积分不足 | 请 充值积分。 |
2003 | 内容被过滤器阻止 | 请修改您的图像,确保内容符合规定。 |
2004 | 图像格式无效 | 请使用支持的图像格式,参考 图像格式详情。 |
2005 | 图像上传失败 | 请验证您的图像数据是否有效,或稍后重试。 |
5050 | 服务器内部错误 | 请联系我们的技术支持团队,并提供 `request_id`。 |
当前支持的图像格式包括:JPG
、JPEG
、PNG
、WebP
。最大图像尺寸为 4MB。
使用 AI 图像标签 API 为您网站的图像自动生成 alt 文本和元描述:
// 使用 AI 生成的标签增强图像 SEO
const enhanceImageSEO = async (imageElement, apiKey) => {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = imageElement.width;
canvas.height = imageElement.height;
ctx.drawImage(imageElement, 0, 0);
const base64Image = canvas.toDataURL('image/jpeg');
const response = await fetch('/api/v1/generate_tags', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify({ image: base64Image })
});
const result = await response.json();
const { tags, title, description } = result.data.tags;
// 更新图像属性以优化 SEO
imageElement.alt = description;
imageElement.title = title;
imageElement.setAttribute('data-tags', tags.join(', '));
};
将 AI 照片标记 功能集成到您的 CMS 工作流程中:
# 在内容管理系统中批量处理图像
import os
import requests
from pathlib import Path
def bulk_tag_images(directory_path, api_key):
"""使用 AI 标记处理目录中的所有图像"""
image_extensions = ['.jpg', '.jpeg', '.png', '.webp']
for image_path in Path(directory_path).iterdir():
if image_path.suffix.lower() in image_extensions:
try:
# 为每张图像生成标签
result = generate_image_tags(api_key, str(image_path))
# 将元数据保存到附加文件中
metadata_path = image_path.with_suffix('.json')
with open(metadata_path, 'w') as f:
json.dump(result['data']['tags'], f, indent=2)
print(f"已处理: {image_path.name}")
except Exception as e:
print(f"处理 {image_path.name} 时出错: {e}")
# 使用方法
bulk_tag_images("/path/to/images", "您的_API_密钥")
如果您对我们的 AI 图像标签 API 或 照片标记服务 有任何疑问或建议,请随时通过以下方式与我们联系:
立即开始使用 AI 图像标签 API,解锁智能照片分类与自动图像标记的强大功能!