# Nutrition & Calories (SBX-BESIN)

Calories and nutrition facts per 100 g for about 7,800 foods, searchable in Turkish and English, with portion weights and a meal and recipe calorie calculator.

Version: v1.0

## Authentication

Send your API key on every request, either as a Bearer token or as the `apikey` query parameter:

```
Authorization: Bearer <YOUR_API_KEY>
https://api.servicebox.io/v1/nutrition/...?apikey=<YOUR_API_KEY>
```

Get a key: sign up at https://servicebox.io/en/signup and create one on the dashboard. An agent can sign up itself with `POST https://api.servicebox.io/v1/accounts` and `{"email": "...", "apis": ["nutrition"]}`: the owner of the mailbox approves by email and the agent collects a short-lived key by polling the returned `poll_url`.

## Base URL

`https://api.servicebox.io`

## Endpoints

### GET /v1/nutrition/calculate

**Calculate a meal or recipe**

The nutrients of a meal or recipe: `items` lists `<food>:<grams>` pairs, comma-separated (up to 30). A food is an id or a name (the best match is used and named in the answer, so check it); grams as `150`, `150g` or `1.5kg`. Answers each item's amounts and `meta.totals`; `meta.partial` lists nutrients some item had no value for (their totals add the known ones). Use when the user asks for the calories or macros of a dish, a recipe or a day's meals.

**Credits:** 1 per call

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `items` | query | string | yes | e.g. `domates:150,beyaz peynir:50,zeytinyağı:10g` or `170457:150`. |

**Example**

```bash
curl "https://api.servicebox.io/v1/nutrition/calculate?items=<items>" \
  -H "Authorization: Bearer $SBX_API_KEY"
```

### GET /v1/nutrition/categories

**List food categories**

The 25 food categories (vegetables, fruits, legumes, dairy and eggs, meats, fish…) in English and Turkish with how many foods each has. Free.

**Credits:** free (0 credits per call)

No parameters.

**Example**

```bash
curl "https://api.servicebox.io/v1/nutrition/categories" \
  -H "Authorization: Bearer $SBX_API_KEY"
```

### GET /v1/nutrition/foods

**Search foods**

About 7,800 foods with calories, protein, fat, carbohydrate, sugars, fibre and salt per 100 g. Search with `q` in Turkish or English (Turkish letters optional: `domates`, `tomato`, `tavuk gogsu`, `beyaz peynir`); the everyday food comes first (raw before prepared). Narrow with `category`. Use when the user asks how many calories or how much protein, fat or carbohydrate a food has, or to find a food's id for /nutrition/foods/{id} or /nutrition/calculate.

**Credits:** 1 per call

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `q` | query | string | no | Words to find at the start of words of the Turkish or English names, Turkish letters optional. |
| `category` | query | string | no | A category id from /nutrition/categories, e.g. vegetables. |
| `limit` | query | integer | no | Items per page, 1–200. |
| `cursor` | query | string | no | The `next_cursor` of the previous page, with the same filters. |

**Example**

```bash
curl "https://api.servicebox.io/v1/nutrition/foods" \
  -H "Authorization: Bearer $SBX_API_KEY"
```

### GET /v1/nutrition/foods/{id}

**Get a food**

One food: every nutrient per 100 g (energy, macronutrients, fats incl. saturated, trans, cholesterol and omega-3, sugars, fibre, sodium and salt, 9 minerals, 13 vitamins, caffeine) and its household portions with their weight (e.g. 1 medium tomato = 123 g). Use after a search when the user wants vitamins, minerals or a portion's weight.

**Credits:** 1 per call

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | integer | yes | A food id from /nutrition/foods, e.g. 170457. |

**Example**

```bash
curl "https://api.servicebox.io/v1/nutrition/foods/1" \
  -H "Authorization: Bearer $SBX_API_KEY"
```

### GET /v1/nutrition/nutrients

**List nutrients**

The nutrients served — key, English and Turkish name, unit and group — and which of them lists carry. Free.

**Credits:** free (0 credits per call)

No parameters.

**Example**

```bash
curl "https://api.servicebox.io/v1/nutrition/nutrients" \
  -H "Authorization: Bearer $SBX_API_KEY"
```

## Errors

Errors are RFC 9457 `application/problem+json` bodies with a machine-readable `type`.

- `401` — the key is missing, unknown, expired or revoked.
- `402` — not enough credits: the body carries `credits_required` and `upgrade_url` (https://servicebox.io/en/pricing).
- `403` — the key is not allowed to call this API.
- `429` — rate limited: wait `retry_after` seconds (also sent as the `Retry-After` header); `upgrade_url` points to a larger plan.

## Links

- OpenAPI document: https://api.servicebox.io/v1/nutrition/openapi.json
- Pricing: https://servicebox.io/en/pricing?api=SBX-BESIN
- API page: https://servicebox.io/en/apis/nutrition
