# openpetfoodfacts.search

**stable** **Advanced**

Open Pet Food Facts: full-text product search.

`GET /v1/openpetfoodfacts/search`

## What you get

A list of Openpetfoodfacts results in Onekey's unified shape, in `data` (an array). An empty array is a normal, successful answer and is charged like any other; a source that reports "nothing found" as an error returns a free `404 not_found` instead.

## What it costs

- **Advanced · 5 credits** for a fresh fetch, charged only when it succeeds.
- **Free when served from cache (0.2 credit for a cached response over 100 KB).**
- **Free** if the request is invalid (never charged) or the source fails or reports not found (refunded).

## Parameters

| Name | Type | Required | Default | What it is | Constraints |
| --- | --- | --- | --- | --- | --- |
| `q` | string | yes | (required) | Search query | max 200 chars; trimmed, repeated spaces collapsed |

## Request

```bash
curl "https://api.onekey.dev/v1/openpetfoodfacts/search?q=royal" \
  -H "x-api-key: YOUR_API_KEY"
```

```python
import requests

res = requests.get(
    "https://api.onekey.dev/v1/openpetfoodfacts/search",
    params={"q": "royal"},
    headers={"x-api-key": "YOUR_API_KEY"},
)
body = res.json()

if body["success"]:
    print(body["data"])
else:
    print(body["error"]["code"], body["error"]["message"])
```

```javascript
const params = new URLSearchParams({ q: "royal" });
const res = await fetch(`https://api.onekey.dev/v1/openpetfoodfacts/search?${params}`, {
  headers: { "x-api-key": "YOUR_API_KEY" },
});
const body = await res.json();

if (body.success) console.log(body.data);
else console.error(body.error.code, body.error.message);
```

## Recorded response

A real Openpetfoodfacts response, recorded and returned in Onekey's shape. Fields the platform does not provide are `null`.

```json
{
  "success": true,
  "data": [
    {
      "entity": {
        "id": "3182550702423",
        "name": "kitten 12mois",
        "category": "dry cat food, Pet-food, open-pet-food-facts"
      },
      "listing": {
        "brand": "Royal canin"
      },
      "ext": {
        "quantity": "2kg",
        "ingredients": "Protéines do volaille déshydratées, nz, isolat de prctéres végétales', graisses animales, mais, gluten de mais, hydrolysat de animalcs, fibres v6g6talcst pulpe do bottorave, levures et de huile de poisson, sels minéraux, huile do sqa, et graires (05 0%), fructod19Œsaccharidos (0,38 %), hydrdysat de bvure dipsaccharides), extrait do rose d'inde (source Méine), ADD(TIFS (au kg) : AddrtJÉ nutrrtmnels: Vitamine A: UI, Vitamim 03: 300 UI, E. El (Fer) : 40 mg, E2 (Iode) : 4 mg, E4 (CuiTe) : 12 E5 (Mavé*) : 52 E6 (Zro : 154 EB : 0,07 A&tfs : tbüte sôdirrmtare : 10 g - CajservatoŒs • CONSTITUANTS ANALYTIQUES : Protéine : 36 % Mabòres grasses brutes : 18 % • CerVes % - brute : % - : 12 MODE :",
        "countries": "France"
      },
      "media": {
        "thumbnailUrl": "https://images.openpetfoodfacts.org/images/products/318/255/070/2423/front_fr.49.400.jpg"
      }
    },
    {
      "entity": {
        "id": "3182550737593",
        "name": "",
        "category": "dry cat food, Pet-food, open-pet-food-facts"
      },
      "listing": {
        "brand": "Royal canin"
      },
      "ext": {
        "quantity": "2kg",
        "ingredients": "Proteine di pollame disidratate, mais, glutine di frumento*, fibre vegetali, grassi animali, proteine animali idrolizzate, riso, frumento, polpa di barbabietola, glutine di mais, prodotti del lievito, sostanze minerali, olio di pesce, fruttoligosaccaridi, olio di soia. \r\nVitamina A: 19000 UI, Vitamina D3: 1000 UI, Ferro (3b103): 31 mg, Iodio (3b201, 3b202): 3,1 mg, Rame (3b405, 3b406): 9 mg, Manganese (3b502, 3b504): 40 mg, Zinco (3b603, 3b605, 3b606): 94 mg, Selenio (3b801, 3b811, 3b812): 0,05 mg - Additivi tecnologici: Clinoptilolite di origine sedimentaria: 10 g - Additivi zootecnici: Cloruro di ammonio: 5 g - Antiossidanti.",
        "countries": "France"
      },
      "media": {
        "thumbnailUrl": "https://images.openpetfoodfacts.org/images/products/318/255/073/7593/front_it.40.400.jpg"
      }
    }
  ],
  "metadata": {
    "platform": "openpetfoodfacts",
    "endpoint": "search",
    "cached": false,
    "stale": false,
    "age_s": 0,
    "fetched_at": "2026-01-01T12:00:00+00:00",
    "credits_charged": 5,
    "request_id": "7f3a9c2e5b1d4c8fa2e6d0b9c4f18e37"
  },
  "error": null
}
```

## Field mapping

How this endpoint's source fields become Onekey's [unified schema](https://onekey.dev/docs/schema.md). Fields the source lacks come back as `null`.

| Source path | Onekey field | Transform |
| --- | --- | --- |
| `code` | `entity.id` | - |
| `product_name` | `entity.name` | - |
| `brands` | `listing.brand` | - |
| `quantity` | `ext.quantity` | - |
| `categories` | `entity.category` | - |
| `ingredients_text` | `ext.ingredients` | - |
| `countries` | `ext.countries` | - |
| `image_front_url` | `media.thumbnailUrl` | `safeUrl` |

## Caching and freshness

- Fresh for about 2 minutes. Repeat calls in that window are served from cache and are free.
- Between 2 minutes and 15 minutes the cached copy is still served instantly and marked `stale: true` while Onekey refreshes it in the background.
- If the source is down when a refresh is needed, the last copy can be served for up to 1 hour more (marked stale).
- A "not found" is remembered for 1 minute and is free.
- The cache is shared across all customers, which is what keeps repeat calls cheap.

## What can go wrong

| Status | Code | What to do |
| --- | --- | --- |
| 401 | `unauthorized` | Check the `x-api-key` header. |
| 402 | `insufficient_credits` | [Add credits](https://onekey.dev/pricing); your balance must cover the price. |
| 404 | `not_found` | Unknown endpoint path. |
| 422 | `invalid_params` | Fix the parameters using the table above. Free. |
| 429 | `rate_limited` | Wait `Retry-After` seconds, then retry. |
| 502 | `upstream_error` | The source failed. Refunded; retry with backoff. |

See [Errors](https://onekey.dev/docs/errors.md) for the full list and retry guidance.

Status: stable (verified against the live source).
