{
  "object": "doc",
  "title": "How do I use Cartroute from any function-calling framework?",
  "description": "A portable JSON Schema tool definition and the handler that calls the API.",
  "section": "Agents and integrations",
  "url": "https://cart-route.com/docs/guides/function-calling",
  "updated": "2026-09-23",
  "prev": "https://cart-route.com/docs/guides/claude",
  "next": "https://cart-route.com/docs/guides/python",
  "text": "Any framework that supports function calling can use Cartroute: register the JSON Schema below as a tool, and when the model calls it, send the arguments to `GET /api/v1/search` and return the JSON response as the tool result. The OpenAPI 3.1 description at [`/openapi.json`](https://cart-route.com/openapi.json) can also be imported directly by frameworks that build tools from OpenAPI.\n\n## What is the portable tool definition?\n\nThis schema is framework-neutral. Most SDKs accept it as the tool's parameters object; some call the field `parameters`, others `input_schema`.\n\n```\n{\n  \"name\": \"search_products\",\n  \"description\": \"Search 12 US retailers (Amazon, Walmart, Best Buy, Costco, Target and more) for a product. Returns every offer with price_usd, shipping_usd, best_coupon and effective_price_usd (price + shipping - best usable coupon). Rank offers on effective_price_usd. price_insight.verdict says whether today's price is a 90-day low. Costco and Sam's Club need a paid membership.\",\n  \"parameters\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"query\": {\n        \"type\": \"string\",\n        \"description\": \"What to find, in plain words. Budgets like \\\"under $400\\\" are understood.\"\n      },\n      \"max_price\": {\n        \"type\": \"number\",\n        \"description\": \"Maximum effective price in USD.\"\n      },\n      \"in_stock\": {\n        \"type\": \"boolean\",\n        \"description\": \"Only in-stock offers. Default true.\"\n      },\n      \"include_membership\": {\n        \"type\": \"boolean\",\n        \"description\": \"Include Costco and Sam's Club. Default true.\"\n      },\n      \"retailers\": {\n        \"type\": \"array\",\n        \"items\": {\n          \"type\": \"string\",\n          \"enum\": [\n            \"amazon\",\n            \"bhphoto\",\n            \"bestbuy\",\n            \"costco\",\n            \"lowes\",\n            \"microcenter\",\n            \"newegg\",\n            \"samsclub\",\n            \"staples\",\n            \"target\",\n            \"homedepot\",\n            \"walmart\"\n          ]\n        },\n        \"description\": \"Limit to these retailers.\"\n      }\n    },\n    \"required\": [\n      \"query\"\n    ]\n  }\n}\n```\n\n## What should the handler do?\n\n```\nimport json\nimport os\nimport requests\n\ndef search_products(query, max_price=None, in_stock=True, include_membership=True, retailers=None):\n    params = {\"q\": query, \"limit\": 3, \"in_stock\": str(in_stock).lower(),\n              \"include_membership\": str(include_membership).lower()}\n    if max_price is not None:\n        params[\"max_price\"] = max_price\n    if retailers:\n        params[\"retailers\"] = \",\".join(retailers)\n    resp = requests.get(\n        \"https://cart-route.com/api/v1/search\",\n        params=params,\n        headers={\"Authorization\": f\"Bearer {os.environ['CARTROUTE_API_KEY']}\"},\n        timeout=20,\n    )\n    # Hand the body back either way: error bodies explain themselves to the model.\n    return json.dumps(resp.json())\n```\n\n## Which other tools are worth adding?\n\n| Tool | Endpoint | When the model should use it |\n\n| `get_product` | `GET /products/{id}` | The user names an exact model, GTIN or a product from an earlier search. |\n\n| `get_price_history` | `GET /products/{id}/price-history` | The user asks whether to buy now or wait. |\n\n| `find_coupons` | `GET /coupons` | The user asks for codes at a specific store. |\n\n## Is there a shortcut if my framework speaks MCP?\n\nYes. If the framework or runtime can connect to remote MCP servers, point it at [`https://cart-route.com/mcp`](https://cart-route.com/docs/mcp) and all seven tools arrive with their schemas, no handler code needed."
}