Build a "Which Card Should I Use?" Endpoint With /v1/cards/best (2026)
A "which card should I use?" feature answers one question per purchase: which card earns the most in this category. CardAPI's GET /v1/cards/best ranks cards by their reward rate in one spending category, and it's on the Free plan. This guide covers the request, what comes back, what the ranking does not do, and the two calls that finish the job: ranking the user's own wallet, and putting points and cash back on one scale.
The request
GET https://api.cardapi.dev/v1/cards/best?category=groceries&country=CA&max_annual_fee=<fee ceiling> Authorization: Bearer ck_live_YOUR_KEY
You get one entry per card, each with that card's highest matching rate in category_rate.
| Parameter | Default | What it does |
|---|---|---|
category | required | A slug from GET /v1/categories. Common aliases such as restaurants and drugstores work. An unknown word, or a label naming several categories, returns an empty list, not an error. A missing category returns 400. |
country | none | US or CA, the issuer's country. |
max_annual_fee | none | A number, 0 or more. Cards whose fee is unknown are left out. |
no_annual_fee | false | Only cards with a stated fee of zero. An unknown fee doesn't count as free. |
include_restricted | false | Also ranks merchant-only, portal-only and pick-your-category rates. |
include_subcategories | false | Also matches child categories, such as online-grocery under groceries. |
merchant_class | none | A store-class slug such as wholesale-clubs. See Store exclusions. |
include_discontinued | false | Also ranks cards closed to new applicants. |
limit | 10 | Values above 50 are treated as 50. |
The boolean flags turn on only with the string true. Full reference: /docs#get-v1-cards-best.
What comes back
category_rate is on every plan. The fields a UI needs:
rate_multiplierwithrate_type(multiplier,points_per_dollarorpercent_cashback). Always show the number with its type.cap_amount,cap_periodandcap_group. Not every rate has a cap; whencap_amountis set, show the period too.merchant, set when the rate applies at one merchant only.choice_group, set when the user picks the category.is_rotating, withrotating_quarterandrotating_year. Only the current quarter's rotating rates are ranked.notes, free text about the rate.
Here is one live result for groceries in Canada, cut to the Free plan. It shows the shape; it isn't a recommendation.
{
"data": [
{
"issuer_id": "61584a90-3975-49ed-b564-5d3f74166e0f",
"slug": "td-first-class-travel-visa-infinite-card",
"name": "TD First Class Travel Visa Infinite Card",
"network": "VISA",
"card_type": "personal",
"annual_fee": 139,
"annual_fee_waived_first_year": true,
"signup_bonus": "Earn up to 160,000 TD Rewards Points: 20,000 welcome bonus points on first purchase plus 140,000 points when you spend $7,500 within 180 days of account opening, plus first-year annual fee rebate",
"signup_bonus_value": 1400,
"signup_min_spend": 7500,
"signup_min_spend_months": 6,
"reward_currency": "points",
"reward_currency_name": "TD Rewards Points",
"referral_bonus_amount": null,
"referral_bonus_url": null,
"product_change_eligible": null,
"product_change_notes": null,
"product_family": null,
"churning_notes": null,
"application_rules": "To receive the first-year Annual Fee rebate for the Primary Cardholder, you must activate your Card and make your first Purchase on the Account within the first 3 months after Account opening.",
"is_discontinued": false,
"signup_bonus_points": 160000,
"signup_bonus_cash_value": 1400,
"issuers": {
"name": "TD",
"slug": "td",
"country": "CA",
"logo_url": null
},
"category_rate": {
"category_slug": "groceries",
"rate_multiplier": 6,
"rate_type": "points_per_dollar",
"cap_amount": 25000,
"cap_period": "annual",
"categories": [
"groceries"
],
"matched_category": "groceries",
"merchant": null,
"booking_channel": null,
"choice_group": null,
"choice_picks": null,
"choice_selection": null,
"excluded_merchants": null,
"excluded_categories": null,
"exclusions_known": false,
"cap_group": null,
"cap_reset": "calendar",
"is_rotating": false,
"rotating_quarter": null,
"rotating_year": null,
"notes": "6 TD Rewards Points for every $1 on groceries, dining and public transit. Each category has its own $25,000 yearly cap. Issuer's terms: \"The TD Rewards Point earn rate for each of Grocery Purchases, Dining Purchases, and Public Transit Purchases is only available on the first $25,000 in annual net Purchases in each category\"."
}
}
]
}Live result at Free-plan values; rates and offers change.
last_verifiednot in a free key's responseStarter plan and aboveRestricted rates and subcategories
By default, best leaves out three kinds of rate:
- Merchant-only: earns only at one named merchant.
- Portal-only: earns only when booked through the issuer's travel portal.
- Pick-your-category: one of several options, and only the picked ones earn.
With them left out, the default answers "where does this card earn this rate anywhere in the category?" Set include_restricted=true when your user does shop at that merchant, books through the portal, or has picked that category. Included rates are flagged by merchant, booking_channel and choice_group.
include_subcategories=true also matches child categories: online-grocery under groceries, airlines and hotels under travel. category_rate.matched_category says which one matched, and on a tie the requested category wins. It doesn't switch on restricted rates.
const base = "https://api.cardapi.dev";
const headers = { Authorization: `Bearer ${process.env.CARDAPI_API_KEY}` };
const url = new URL(`${base}/v1/cards/best`);
url.searchParams.set("category", "groceries");
url.searchParams.set("country", "CA");
url.searchParams.set("include_subcategories", "true");
url.searchParams.set("max_annual_fee", String(feeCeiling)); // from your user's settings
const { data: cards } = await (await fetch(url, { headers })).json();Store exclusions: merchant_class
A grocery rate may not pay at a warehouse club or a superstore, because some issuers leave those stores out of their grocery definition. To rank with that in mind, pass the store class:
url.searchParams.set("merchant_class", "wholesale-clubs");Rates whose excluded_categories include that class drop out. A rate with exclusions_known: false stays: it means CardAPI hasn't read that rate's exclusions yet, not that nothing is excluded. Tell your users so.
Exclusions have been read for only some rates, so this filter won't change every result. Treat it as "drop the rates known to exclude this store", not as a promise about a store. It also takes a category slug, not a store name: map "Costco" to wholesale-clubs yourself.
The published @cardapi/client 0.4.0 has no option for merchant_class or include_subcategories, which is why these samples call the API with fetch.
The ranking compares numbers, not value
best sorts by the raw rate_multiplier, whatever the rate_type. Six points per dollar ranks above 5% cash back even when the points are worth less. The API doesn't convert points to cents; your code does.
GET /v1/reward-valuations returns CardAPI's estimates, in cents per point, for each reward currency. Cards carry reward_currency_name, not a currency code, so match it to the valuation's currency_name. Names can be close across programs, so review your matches rather than trusting a substring blindly. percent_cashback is already cents per dollar.
const { data: valuations } = await (await fetch(`${base}/v1/reward-valuations`, { headers })).json();
function centsPerDollar(card, rate) {
if (rate.rate_type === "percent_cashback") return rate.rate_multiplier;
const name = card.reward_currency_name;
const program = name && valuations.find(v =>
name.includes(v.currency_name) || v.currency_name.includes(name)
);
if (!program) return null; // no match: don't guess a value
return rate.rate_multiplier * program.cpp_recommended;
}These are estimates. Label them as such, show the cents-per-point figure you used, and don't tell a user it's what their points are really worth.
Ranking the user's own wallet
best ranks the market; it doesn't know which cards the user holds. For the wallet, call GET /v1/cards/compare?slugs=a,b,c with 2 to 5 different slugs. Cards come back in the order you asked, with no category_rate, so you pick each card's rate:
- Match on
categories. - Skip merchant-only and portal-only rates unless they apply.
- Treat a
choice_grouprate as "depends on the user's pick." - Fall back to the base rate (
is_base_rate) when nothing matches.
On the Free plan, each card returns only its top 3 reward_rates, so a wallet card can show no grocery rate even when it has one. Every rate needs the Starter plan or above.
Don't work around that by calling best with a high limit and intersecting with the wallet: the list stops at 50 cards, so a wallet card can fall off the end. The rewards optimizer use case has a full scorer, including pick-your-category rates.
Caching and limits
The API caches best for 5 minutes per plan and URL, and categories and valuations for 30 minutes. Cache on your side too; the terms allow you to "store or cache API responses in order to do that." Request limits per plan are on /docs/rate-limits.
Licence
Your endpoint can serve your own app. CardAPI's terms say:
While your plan is active, you may display CardAPI data to the users of your own website, app, product or content, and store or cache API responses in order to do that.
A public recommendation API for other developers is different. The terms say you may not:
Re-serve the raw data to others: offer it through an API or data feed of your own, as a CSV or spreadsheet download, or as any other bulk export. An API that only your own site or app uses to show the data to its users is fine.
Full text: cardapi.dev/terms.
Next
CardAPI's MCP server, @cardapi/mcp, runs locally with your own key. Its best_card_for_category tool takes the same inputs as this endpoint. In Claude Code:
claude mcp add --env CARDAPI_API_KEY=YOUR_CARDAPI_KEY --transport stdio cardapi -- npx -y @cardapi/mcp
Other clients: /docs/mcp.
Start with the quickstart, or see the comparison-site guide and the AI agents guide. Get a free key. No credit card required.
Related guides
- Credit card data APIs compared: CardAPI next to other credit card data APIs, each row from that product's own public pages and dated.
- Give an AI agent live credit card data: Tool definitions and handler code for an LLM agent, plus the MCP server for Claude, Cursor and VS Code.
- MCP is live: CardAPI's card data in Claude and Cursor: What the MCP server is, questions to ask it, how to install it, the tools each plan can use and where it is listed.
- Plaid + CardAPI: from a linked card to its reward rates: Match a Plaid credit account to a card, have the user confirm it, then score transactions by category.
- Build a credit card comparison site with Next.js: A step-by-step walkthrough with the SDK and incremental static regeneration.