Give an AI Agent Live Credit Card Data: Tool Calling With CardAPI (2026)
Using Claude, Cursor or VS Code? You can skip the code below: CardAPI's MCP server gives your assistant these tools on your own key. Setup takes a few lines, on /docs/mcp.
A model answers card questions from its training data, and that data is a snapshot. Annual fees, earn rates, caps and welcome offers change, and the model can't see changes made after its training ended. If your assistant tells a user what a card earns, the answer should come from a live source.
This guide gives an agent three tools over CardAPI's REST API. It is plain tool calling: you define the tools, the model asks to use one, and your code makes the request and returns the result. It works with any model and needs no MCP client. CardAPI also has an MCP server you can run yourself, covered below and on /docs/mcp.
The three tools
search_cardsfinds cards by card or issuer name. It wrapsGET /v1/cards/search. Search results don't include thereward_rateslist, so the model should callget_cardfor rates.get_cardreturns one card by slug. It wrapsGET /v1/cards/{slug}. Which fields come back depends on your plan.best_card_for_categoryranks cards by reward rate in one spending category. It wrapsGET /v1/cards/bestand answers questions like "which card should I use for groceries?"
Category slugs come from GET /v1/categories. You can list them in the tool description, or fetch them once at start-up and cache them.
Tool definitions
Each tool has a name, a description and an input_schema written in JSON Schema. The definitions below use Claude's format. OpenAI function calling takes the same name, description and JSON Schema, declared as type: "function" with the schema under parameters. See the Claude tool use overview and the OpenAI function calling guide.
[
{
"name": "search_cards",
"description": "Search credit cards by card or issuer name. Results do not include reward rates; call get_card for a card's rates and fees.",
"input_schema": {
"type": "object",
"properties": {
"q": { "type": "string", "maxLength": 200, "description": "Card or issuer name to search for." },
"country": { "type": "string", "enum": ["US", "CA"], "description": "Only return cards from issuers in this country." }
},
"required": ["q"]
}
},
{
"name": "get_card",
"description": "Get one credit card by its slug, for example american-express-gold-card. Returns the fields included in the caller's plan.",
"input_schema": {
"type": "object",
"properties": {
"slug": { "type": "string", "description": "The card's slug, as returned by search_cards." }
},
"required": ["slug"]
}
},
{
"name": "best_card_for_category",
"description": "Rank credit cards by reward rate for one spending category. Each result has the matching rate, and any cap, in category_rate. Rates limited to one merchant, to the issuer's travel portal, or to a pick-your-category choice are left out.",
"input_schema": {
"type": "object",
"properties": {
"category": { "type": "string", "description": "Spending category slug from GET /v1/categories, for example groceries, dining or gas." },
"country": { "type": "string", "enum": ["US", "CA"], "description": "Country of the cards to rank." },
"max_annual_fee": { "type": "number", "minimum": 0, "description": "Only cards with an annual fee at or below this amount." },
"merchant_class": { "type": "string", "description": "Store class slug, for example wholesale-clubs. Drops rates that say they don't apply at this kind of store." },
"limit": { "type": "integer", "minimum": 1, "maximum": 50, "description": "How many cards to return. Default 10." }
},
"required": ["category"]
}
}
]The tool handler
Your server runs each tool call, so the model never sees your key. This handler uses the @cardapi/client SDK and maps each tool to one method.
import { CardAPI, CardAPIError } from "@cardapi/client";
const api = new CardAPI({ apiKey: process.env.CARDAPI_API_KEY }); // server side only
async function runTool(name, input) {
try {
switch (name) {
case "search_cards":
return await api.searchCards(input.q, input.country);
case "get_card":
return await api.getCard(input.slug);
case "best_card_for_category":
return await api.getBestCards(input.category, {
country: input.country,
maxAnnualFee: input.max_annual_fee,
merchantClass: input.merchant_class,
limit: input.limit,
});
default:
return { error: `Unknown tool: ${name}` };
}
} catch (err) {
if (err instanceof CardAPIError) {
return { error: err.message, status: err.status, suggestions: err.suggestions };
}
throw err;
}
}Send the return value back to the model as the tool result. When get_card gets a slug it doesn't know, the API answers 404 with up to five suggested slugs, which the SDK puts in err.suggestions. Passing them back lets the model retry.
An example turn
The user asks: "Which card should I use for groceries in Canada?"
The model calls:
{
"name": "best_card_for_category",
"input": { "category": "groceries", "country": "CA", "limit": 1 }
}Your handler sends GET /v1/cards/best?category=groceries&country=CA&limit=1. Here is what that call returns as of today's refresh, with free-key fields only:
{
"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\"."
}
}
]
}The model should answer from the tool result alone. A good answer names the card, gives its grocery rate from category_rate (read rate_multiplier together with rate_type, which says whether it is a multiplier, cash back percent or points per dollar), and states any cap and cap period. Something like: "For groceries in Canada, the top result is {name}. It earns {rate} on groceries, up to {cap_amount} per {cap_period}." That describes a ranking. It doesn't make the card the right choice for every user, so the agent shouldn't call it "the best card".
last_verifiednot in a free key's responseStarter plan and aboveA free key does not return it, so the agent can't cite a check date.
What the agent should say carefully
Reward rates come with conditions. An agent that drops them gives wrong answers.
- Caps.
category_ratecarriescap_amountandcap_period(monthly, quarterly or annual). A rate with a monthly cap doesn't apply to all spending, so the agent should say the cap. - Restricted rates. By default,
/v1/cards/bestleaves out rates limited to one merchant, to the issuer's travel portal, or to a pick-your-category choice. The tool above never sendsinclude_restricted, so those rates don't appear. If you need them, add the parameter to the schema and passincludeRestrictedin the handler. - Store classes. A grocery rate may not apply at every store that sells groceries. Pass
merchant_class(for examplewholesale-clubs) when the user shops at a warehouse club. It drops rates whose excluded store classes include it. Rates whose exclusions CardAPI hasn't read yet (exclusions_knownis false) stay in, so the agent should flag that. - Rotating rates. Only the current quarter's rotating rates count.
category_rategivesrotating_quarterandrotating_year, so the agent can say which quarter the answer covers. - Online grocery.
groceriesmeans grocery stores. Online grocery orders are a separate category,online-grocery.
See /docs/reward-rates for every field on a rate.
Caching and rate limits
A free key allows 100 requests a day and 3,000 a month. Limits for every plan are on /docs/rate-limits.
One conversation can trigger several tool calls, so cache results, for example by category and country. The terms allow caching responses in order to show the data to your own users.
Licence
Answering your own users is fine. Your assistant can quote a card's fee or earn rate in a reply, and you can cache results to do that.
CardAPI's terms list what you may not do. The first item:
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.
The terms also bar using CardAPI data to build a competing credit card database or data product. So don't expose these tools as an API other companies can call, and don't export the catalogue.
MCP servers and other options
MCP servers give a model card tools without your own handler code.
- CardAPI has a local MCP server,
@cardapi/mcp. Run it withnpx -y @cardapi/mcpand your own CardAPI key (a free key needs no credit card). Every tool call is one call to the REST API on your key (get_card_benefitsmakes two), so it follows the same plan rules and quota as the tools in this guide. Setup for Claude, Cursor and VS Code is on /docs/mcp. - StackEasy runs a read-only remote MCP server. Its FAQ says every tool, catalogue lookups included, runs through a signed-in StackEasy account, which costs $25 a month after a 14-day trial.
- CardSavvy runs a remote MCP server at
mcp.card-savvy.com/mcp. Its catalogue and per-purchase tools need no account, and a free token unlocks its optimizer tools. Its own article says there is no paid tier. - CardPointers offers an MCP server for its own users, included with CardPointers+. Using it in ChatGPT needs a paid ChatGPT plan.
The other three are described from their public pages, read 6 December 2026. Tell us if anything changed.
CardAPI works through ordinary tool calling, as shown above, or through its own MCP server. For how CardAPI compares with other card data APIs, see the comparison guide. To start, get a free key and follow the quickstart. The rewards optimizer use case shows how to pick the best card in a user's own wallet.
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.
- 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.
- A "which card should I use?" endpoint with /v1/cards/best: Rank cards by what they earn in a spending category: the filters, store exclusions, wallet ranking and point values.
- Build a credit card comparison site with Next.js: A step-by-step walkthrough with the SDK and incremental static regeneration.