Skip to content

GET /api/keepa/graphimage

获取产品价格历史图表 PNG 图片,可直接嵌入网页 / Markdown / 邮件中展示。

对应 Keepa 官方接口:Graph Image API

接口

GET https://mcp.keepamore.com/api/keepa/graphimage

计费

项目units
任意一次成功调用1

任何曲线开关 / 尺寸 / 配色参数都不会改变本接口的计费金额。

参数(Query String)

名称类型必填默认说明
domaininteger站点 ID,参见 domain 映射。也可用 domainId / country 别名
asinstringASIN(自动 uppercase)
amazon / new / used / salesrank / bb / fba / fbm / ld / wd0/1控制绘制哪些曲线
rangeinteger90日期范围(天)
width / heightinteger500 / 200图片尺寸
cbackground / cfont / camazon / cnew / cused / csales / cfba / cfbm / cbb / cld / cwdstring配色参数
yzoom0/1纵轴缩放

安全白名单:参数名经小写归一化后,只接受上面列出的字段;未知字段会被静默丢弃。key 不会被透传到上游。

响应

Content-Type: image/png,直接是 PNG 二进制。响应头:

Header含义
Content-Typeimage/png
X-CacheHIT / MISS
X-Response-Time总耗时
X-Units-Consumed扣减 units

不是 JSON,错误时仍按统一 JSON 结构返回(鉴权失败、额度不足、Keepa 异常等)。

示例

bash
# 请将 km_xxx 替换为你的 API Key
# 保存到本地
curl -o history.png \
  "https://mcp.keepamore.com/api/keepa/graphimage?domain=1&asin=B08N5WRWNW&range=180&width=800&height=300" \
  -H "X-API-Key: km_xxx"

# 作为 data URL 内嵌到页面
curl -s "https://mcp.keepamore.com/api/keepa/graphimage?domain=1&asin=B08N5WRWNW" \
  -H "X-API-Key: km_xxx" \
  | base64 -w 0
js
// 请将 km_xxx 替换为你的 API Key
// 保存到本地
const resp = await fetch(
	"https://mcp.keepamore.com/api/keepa/graphimage?domain=1&asin=B08N5WRWNW&range=180&width=800&height=300",
	{ headers: { "X-API-Key": "km_xxx" } },
);
const buffer = await resp.arrayBuffer();
// 写入文件 (Node.js)
import { writeFileSync } from "node:fs";
writeFileSync("history.png", Buffer.from(buffer));

// 作为 data URL 内嵌
const base64 = Buffer.from(buffer).toString("base64");
const dataUrl = `data:image/png;base64,${base64}`;
python
# 请将 km_xxx 替换为你的 API Key
import requests, base64

URL = "https://mcp.keepamore.com/api/keepa/graphimage"
HEADERS = {"X-API-Key": "km_xxx"}

# 1) 保存到本地
r1 = requests.get(URL,
                  params={"domain": 1, "asin": "B08N5WRWNW",
                          "range": 180, "width": 800, "height": 300},
                  headers=HEADERS, timeout=60)
with open("history.png", "wb") as f:
    f.write(r1.content)

# 2) 作为 data URL 内嵌
r2 = requests.get(URL, params={"domain": 1, "asin": "B08N5WRWNW"},
                  headers=HEADERS, timeout=60)
data_url = f"data:image/png;base64,{base64.b64encode(r2.content).decode()}"
php
<?php
// 请将 km_xxx 替换为你的 API Key
require 'vendor/autoload.php';
use GuzzleHttp\Client;

$client = new Client();
$resp = $client->get('https://mcp.keepamore.com/api/keepa/graphimage', [
    'headers' => ['X-API-Key' => 'km_xxx'],
    'query'   => [
        'domain' => 1, 'asin' => 'B08N5WRWNW',
        'range'  => 180, 'width' => 800, 'height' => 300,
    ],
    'timeout' => 60,
]);
file_put_contents('history.png', (string) $resp->getBody());
java
// 请将 km_xxx 替换为你的 API Key(Java 11+ 标准库)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Path;
import java.time.Duration;

HttpClient client = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder()
    .uri(URI.create("https://mcp.keepamore.com/api/keepa/graphimage?domain=1&asin=B08N5WRWNW&range=180&width=800&height=300"))
    .header("X-API-Key", "km_xxx")
    .timeout(Duration.ofSeconds(60))
    .GET()
    .build();
HttpResponse<Path> resp = client.send(req, HttpResponse.BodyHandlers.ofFile(Path.of("history.png")));
System.out.println("saved -> " + resp.body());
go
// 请将 km_xxx 替换为你的 API Key(Go 标准库 net/http)
package main

import (
    "io"
    "net/http"
    "os"
    "time"
)

func main() {
    req, _ := http.NewRequest("GET",
        "https://mcp.keepamore.com/api/keepa/graphimage?domain=1&asin=B08N5WRWNW&range=180&width=800&height=300", nil)
    req.Header.Set("X-API-Key", "km_xxx")

    client := &http.Client{Timeout: 60 * time.Second}
    resp, err := client.Do(req)
    if err != nil { panic(err) }
    defer resp.Body.Close()

    f, _ := os.Create("history.png")
    defer f.Close()
    io.Copy(f, resp.Body)
}

典型配方

场景关键参数
默认 90 天 Amazon 价格domain + asin
长周期(180 天)大图range=180&width=1000&height=400
仅 New 价格 + 销量排名amazon=0&new=1&used=0&salesrank=1
自定义品牌色cbackground=ffffff&camazon=ff9900&cnew=232f3e

和 MCP 的对应