首页 开发文档 菜谱识别

菜谱识别

上传菜品图片识别菜谱。默认同步返回结果;传 async=1 走异步:立即返回 task_id,结果通过 callback_url 回调(HMAC-SHA256 签名,密钥为你的接口密钥)或调用任务查询接口获取。图片传公网 URL 或 base64。上游处理较慢时,同步请求超过等待秒数会自动转为异步返回 task_id,可凭 task_id 调用任务查询接口获取最终结果,失败自动退款。

请求信息
请求地址 https://www.cx4.cn/openApi/ai/recipe_recognize 复制
请求方式 GET / POST
接口标识 recipe_recognize
鉴权方式 必须
四种方式任选其一:Header「X-Api-Key」/ Header「Authorization: Bearer 你的key」/ URL 参数「?key=你的key」/ POST 参数「key」
请求参数
参数名 类型 必填 说明 示例
image string 是 菜品图片,支持公网 URL 或 base64(推荐 URL,body 更小) https://example.com/dish.jpg
async int 否 是否异步:0 同步直接返回结果(默认);1 异步提交,立即返回 task_id(需配合回调或任务查询) 0
callback_url string 否 异步回调地址(仅 async=1 生效),必须是公网 http(s);有结果时 POST 通知,HMAC-SHA256 签名 https://example.com/cb
返回参数

下表字段位于返回结构的 data 内;外层 code / message 为全平台统一格式,不在此重复列出。

参数名 类型 说明 示例
name string 识别出的菜名 番茄炒蛋
ingredients array 食材清单 [{"name":"番茄","amount":"2个"}]
ingredients[].name string 食材名称 番茄
ingredients[].amount string 用量 2个
steps array 制作步骤 [{"step":1,"text":"番茄切块"}]
steps[].step int 步骤序号 1
steps[].text string 步骤描述 番茄切块
cook_time string 预计耗时 15分钟
difficulty string 难度:简单/中等/困难 简单
tips string 烹饪小贴士 先炒蛋再炒番茄
confidence float 识别置信度 0-1 0.95
task_id string 同步请求超过系统配置的等待秒数仍未完成时自动转为异步,返回任务 ID;凭此调用「任务查询」接口获取结果 20261120a1b2c3d4e5
status string 仅转为异步时返回,任务状态 pending(同步完成时本字段不出现,直接返回业务结果) pending
返回示例

成功

{"code":200,"message":"操作成功","data":{"name":"番茄炒蛋","ingredients":[{"name":"番茄","amount":"2个"}],"steps":[{"step":1,"text":"番茄切块"}],"cook_time":"15分钟","difficulty":"简单","confidence":0.95}}

// async=1 时:
{"code":200,"message":"操作成功","data":{"task_id":"20261120a1b2c3d4","status":"pending"}}

失败

{
    "code": 500,
    "message": "智能识别失败:上游未返回合法 JSON",
    "data": null
}
平台通用状态码
状态码 说明
200调用成功
400缺少必填参数或参数格式有误
401密钥缺失或无效
402余额不足,请充值后重试
403未开通该接口,请在本页开通后调用
404接口不存在或已下架
429触发限流,请稍后重试
500接口调用失败(已扣款的会自动退款)
调用示例

cURL 复制

curl -X POST "https://www.cx4.cn/openApi/ai/recipe_recognize" -H "X-Api-Key: 你的SecretKey" -d "image=https://example.com/dish.jpg&async=0&callback_url=https://example.com/cb"

JavaScript 复制

fetch('https://www.cx4.cn/openApi/ai/recipe_recognize', {
  method: 'POST',
  headers: {
    'X-Api-Key': '你的SecretKey',
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: 'image=https://example.com/dish.jpg&async=0&callback_url=https://example.com/cb'
})
.then(res => res.json())
.then(data => console.log(data));

PHP 复制

<?php
require 'vendor/autoload.php';

$client = new \GuzzleHttp\Client();
$response = $client->post('https://www.cx4.cn/openApi/ai/recipe_recognize', [
    'headers' => ['X-Api-Key' => '你的SecretKey'],
    'form_params' => ['image' => 'https://example.com/dish.jpg', 'async' => '0', 'callback_url' => 'https://example.com/cb'],
]);
echo $response->getBody();

Java 复制

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://www.cx4.cn/openApi/ai/recipe_recognize"))
    .header("X-Api-Key", "你的SecretKey")
    .header("Content-Type", "application/x-www-form-urlencoded")
    .POST(HttpRequest.BodyPublishers.ofString("image=https://example.com/dish.jpg&async=0&callback_url=https://example.com/cb"))
    .build();
HttpResponse<String> response = client.send(
        request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

Python 复制

import requests

res = requests.post('https://www.cx4.cn/openApi/ai/recipe_recognize',
    headers={'X-Api-Key': '你的SecretKey'},
    data={'image': 'https://example.com/dish.jpg', 'async': '0', 'callback_url': 'https://example.com/cb'})
print(res.json())
在线测试 (使用你的密钥真实调用,计费与正常调用一致)

登录后可在线测试: 立即登录

计费说明

¥0.2000

每次调用


每日免费额度:无

累计调用:21 次


快速上手

1. 注册并完成邮箱验证:立即注册

2. 登录后复制 Secret Key:去登录

3. 点击右侧「开通接口」按钮

4. 用下方「在线测试」一键体验,或复制下方示例代码直接调用