服务
图片识别 API
一次付费的 HTTP 调用,传入一张图片和可选的问题,以纯文本或 Markdown 返回答案。
概述
一次 POST 传入一张图片(图片 URL,或一个 Base64 字符串)和可选的提示词。本地文件可以直接用 Base64 传入,无需先上传。响应里是你选择的格式的答案。
匿名调用用 x402 在 Base 上付款,无需账号或 API Key。付款流程和所有服务共用的规则见平台文档。
POST https://api.koinelix.com/v1/images/recognitions快速开始
curl 用于获取报价;核对后,切换到 TypeScript 或 Python 示例发起付费调用。
example.com 图片地址仅用于演示 URL 写法,实际调用前请替换为可访问的图片地址。
第一次使用 x402?先看准备指南 →# example.com is a placeholder. Replace it with an accessible image URL before calling.
# 1. Ask for a quote. No payment, no account.
curl -i -X POST https://api.koinelix.com/v1/images/recognitions \
-H 'Content-Type: application/json' \
-d '{"image_url":"https://example.com/photo.jpg","prompt":"What is in this image?","output_format":"markdown"}'
# HTTP/2 402
# PAYMENT-REQUIRED: <base64 x402 v2 quote: price, network, asset, payee>
#
# 2. An x402 client signs that quote with your wallet and repeats the same request
# with a PAYMENT-SIGNATURE header. See the TypeScript and Python tabs.- 钱包秘密仅在你自己的执行环境中管理,不要在本网站填写私钥或助记词。
- 客户端超时请设为至少 120 秒,并保持连接直到收到响应。
- 连接中断或超时后,用同一个 PAYMENT-SIGNATURE 重发同一个请求,不要重新付款。
使用 API Key 调用
使用平台 API Key 时,调用优先使用你账号的次数;次数用完才返回 x402 报价。
API Key 调用使用账号额度;注册和创建 Key 不赠送额度。
# image_b64 is ONE standard Base64 string without a data: prefix (not an array).
# A photo is too big for a command-line argument, so the body goes through a file.
IMAGE_B64=$(base64 < photo.png | tr -d '\n')
printf '{"image_b64":"%s","prompt":"List the items on this receipt","output_format":"markdown"}' "$IMAGE_B64" > body.json
curl -sS -X POST https://api.koinelix.com/v1/images/recognitions \
-H "Authorization: Bearer $KOINELIX_API_KEY" \
-H 'Content-Type: application/json' \
--max-time 120 \
--data-binary @body.json- 用 Authorization: Bearer <你的 API Key> 发送密钥。Idempotency-Key 是可选的。
- 用同一个 Idempotency-Key 和相同的请求体重发,会返回原请求,不会开始新的调用。
请求体
发送 JSON 请求体,Content-Type: application/json。image_url 和 image_b64 必须恰好提供一个。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
image_url | string | 二选一 | 图片的绝对 http 或 https URL,最多 2048 个字符。 |
image_b64 | string | 二选一 | 图片的标准带填充 Base64 字符串,单行,不带 data: 前缀;png、jpeg、webp 或 gif,解码后最多 10 MiB。它是一个字符串,不是数组。用代码生成并放进请求体(例如 base64 < photo.png | tr -d "\n"),上限以内的图片都可以这样发送。如果客户端是逐字手写工具调用参数,长字符串容易出错,请改用 image_url、让代码来构造请求,或只发送一张小缩略图。 |
prompt | string | 否 | 你想了解这张图片的什么,最多 4000 个 UTF-8 字节。不传时使用默认的描述请求。 |
output_format | "text" | "markdown" | 否 | 答案的格式:text(默认)或 markdown。 |
请求体示例
{
"image_url": "https://example.com/photo.jpg",
"prompt": "What is in this image?",
"output_format": "markdown"
}响应
调用成功返回 HTTP 200 和 JSON 响应体。
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 这次调用的标识。 |
created | integer | Unix 时间,单位为秒。 |
format | "text" | "markdown" | 这份答案的格式。 |
content | string | null | 答案。原请求的答案已送达后再次用同一请求重发时为 null。 |
truncated | boolean | 答案被截断到大小上限时为 true。 |
{
"id": "c_0123456789abcdef",
"created": 1767225600,
"format": "markdown",
"content": "A tabby cat sitting on a wooden windowsill.",
"truncated": false
}付款时,PAYMENT-RESPONSE 头携带 x402 结算信息。
错误
错误使用与所有 Koinelix API 相同的 JSON 错误格式。通用的付款和请求错误见平台文档。
| HTTP | 错误码 | 处理方式 |
|---|---|---|
| 400 | validation_failed | 请求体无效,error.param 指出字段。修正后重新发送。 |
| 409 | request_in_progress | 这个密钥或签名对应的原请求仍在执行。请等待后再重发。 |
| 422 | upstream_rejected | 图片或提示词无法处理。请确认图片可读、提示词有效。 |
| 502 | recognition_failed | 识别请求失败,请稍后重试。 |
| 502 | recognition_empty | 模型没有返回答案,请换一张图片或提示词。 |
| 502 | recognition_not_started | 请求没能发出,请稍后重试。 |
| 503 | capacity_unavailable | 暂时没有可用容量,请稍后重试。 |
| 503 | service_not_configured | 服务尚未开放。 |
| 504 | recognition_timeout | 请求超时,请稍后重试。 |