How to use Open Food Facts with Mastra

Integrate Open Food Facts into your Mastra agent with SettleGrid's per-call billing. No subscriptions, no minimums — pay only for what you use.

About Open Food Facts

Global food product database with nutrition data, ingredients, and allergens.

Search & Discoveryv1.0.0by Lex Whiting

About Mastra

Mastra is a TypeScript-first framework for building AI agents and workflows. It provides type-safe tool definitions and composable agent pipelines.

TypeScript

Integration Guide

1

Install Mastra

Terminal
npm install mastra
2

Get your SettleGrid API key

Purchase credits for Open Food Facts, then generate an API key from your Consumer Dashboard.

3

Register Open Food Facts in your Mastra agent

TypeScript
import { Agent, createTool } from "mastra";
import { z } from "zod";

// Define the tool with Zod schema
const open_food_factsTool = createTool({
  id: "open_food_facts",
  description: "OpenFoodFacts — call via SettleGrid",
  inputSchema: z.object({
    query: z.string().describe("Input query"),
  }),
  execute: async ({ context }) => {
    const resp = await fetch(
      "https://proxy.settlegrid.ai/v1/open_food_facts",
      {
        method: "POST",
        headers: {
          "x-api-key": "sg_live_your_key_here",
          "Content-Type": "application/json",
        },
        body: JSON.stringify({ query: context.query }),
      }
    );
    if (!resp.ok) throw new Error(`OpenFoodFacts failed: ${resp.status}`);
    return resp.json();
  },
});

// Create an agent with the tool
const agent = new Agent({
  name: "open_food_facts-agent",
  instructions: "Use OpenFoodFacts to accomplish the task.",
  model: { provider: "OPEN_AI", name: "gpt-4o" },
  tools: { open_food_facts: open_food_factsTool },
});

const result = await agent.generate("Use OpenFoodFacts for this input");
4

Run your agent

Execute your Mastra agent. SettleGrid automatically meters each call to Open Food Facts and deducts from your credit balance. No rate limits beyond your purchased credits.

Pricing

Cost per call2¢

No subscriptions or minimums. Credits never expire. See full pricing details.

Try Open Food Facts

Purchase credits and start using Open Food Facts in your Mastra agent today.

View Open Food Facts →

Other Frameworks

Use Open Food Facts with other agent frameworks:

SettleGrid Help

AI-powered support

How can I help?

Ask me anything about SettleGrid