AI agents & tools
AllNutrition is built to be wired straight into LLM agents. The API is described by a full OpenAPI 3.1 spec, returns structured JSON with evidence labels, and is unauthenticated for public use — meaning it's a one-line tool registration in any agent framework.
The 30-second pitch (for your model's system prompt)
You have access to the AllNutrition API, an evidence-based nutrition service.
Use the `ask_nutrition` tool whenever the user asks about nutrition, diet,
supplements, micronutrients, dosages, or food–health relationships.
The tool returns:
- `answer`: a Markdown answer grounded in peer-reviewed sources
- `evidence_strength`: strong | moderate | limited | insufficient
- `consensus_level`: high | moderate | mixed | low
- `sources`: an array of citations (title, publisher, url, evidence_level, trust_score)
When relaying to the user, always include the `answer` AND surface at least the
top 1–2 sources by `trust_score`. If `evidence_strength` is "insufficient",
say so plainly and suggest consulting a clinician.
OpenAI tool use
Register the public endpoint as a function the model can call.
from openai import OpenAI
import httpx
client = OpenAI()
TOOLS = [{
"type": "function",
"function": {
"name": "ask_nutrition",
"description": (
"Answer a nutrition question with citations to peer-reviewed research, "
"clinical guidelines, and expert position statements. Returns an evidence-tagged "
"answer. Use whenever the user asks about diet, nutrition, supplements, or food–health relationships."
),
"parameters": {
"type": "object",
"properties": {
"question": {"type": "string", "description": "The nutrition question, in plain English."}
},
"required": ["question"],
},
},
}]
def ask_nutrition(question: str) -> dict:
r = httpx.post(
"https://www.allnutrition.info/api/v1/ask",
json={"question": question},
timeout=60,
)
r.raise_for_status()
return r.json()
resp = client.chat.completions.create(
model="gpt-4o-mini",
tools=TOOLS,
messages=[{"role": "user", "content": "How much vitamin D should I take daily?"}],
)
# ... dispatch tool calls and feed `ask_nutrition(...)` back into the model
Anthropic Claude tool use
import anthropic, httpx
client = anthropic.Anthropic()
TOOLS = [{
"name": "ask_nutrition",
"description": (
"Answer a nutrition question with citations to peer-reviewed research and "
"clinical guidelines. Returns evidence_strength (strong|moderate|limited|insufficient) "
"and a list of sources. Always cite at least one source when relaying the answer."
),
"input_schema": {
"type": "object",
"properties": {
"question": {"type": "string", "description": "Plain-English nutrition question."}
},
"required": ["question"],
},
}]
def ask_nutrition(question: str) -> dict:
return httpx.post(
"https://www.allnutrition.info/api/v1/ask",
json={"question": question}, timeout=60,
).json()
msg = client.messages.create(
model="claude-opus-4-7",
max_tokens=1024,
tools=TOOLS,
messages=[{"role": "user", "content": "Is creatine safe for teens who lift?"}],
)
# Loop on tool_use blocks, call ask_nutrition(question), and pass the JSON result
# back as a tool_result content block.
Custom GPTs / GPT Actions
Skip the boilerplate — point a Custom GPT directly at the OpenAPI spec.
- In ChatGPT, go to Create a GPT → Configure → Actions → Create new action.
- Click Import from URL and paste:
https://www.allnutrition.info/openapi.json - Authentication: None.
- In the GPT's instructions, tell it to call
askNutritionQuestionfor any nutrition-related user message and to surface at least one source from thesourcesarray.
Operation IDs that match what GPT shows you:
askNutritionQuestion, searchReferences, publicHealth.
LangChain
from langchain.tools import tool
import httpx
@tool
def ask_nutrition(question: str) -> dict:
"""Answer a nutrition question with citations to peer-reviewed research.
Returns an evidence-tagged answer (strong/moderate/limited/insufficient) and a
list of sources. Use for any diet, nutrition, supplement, or food-health question.
"""
r = httpx.post(
"https://www.allnutrition.info/api/v1/ask",
json={"question": question}, timeout=60,
)
r.raise_for_status()
return r.json()
Vercel AI SDK
import { tool } from "ai";
import { z } from "zod";
export const askNutrition = tool({
description:
"Answer a nutrition question with citations to peer-reviewed research. " +
"Use for any diet, nutrition, supplement, or food-health question.",
parameters: z.object({
question: z.string().describe("The nutrition question, in plain English."),
}),
execute: async ({ question }) => {
const r = await fetch("https://www.allnutrition.info/api/v1/ask", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ question }),
});
if (!r.ok) throw new Error(`HTTP ${r.status}`);
return r.json();
},
});
Best practices
-
Always show the citations. The point of AllNutrition is the
evidence trail. If your agent only relays the
answerstring, you've stripped the differentiator. -
Respect
evidence_strength. When it's"insufficient", the model should not paraphrase the answer as a recommendation — say "the evidence is insufficient" and suggest a clinician. - Cache popular questions. 10 requests / IP / day is generous for individual users but tight for shared tools — cache by normalised question to stretch the budget.
- Don't diagnose. AllNutrition explicitly avoids medical advice; your wrapper should mirror that — pair every answer with a "consult a clinician for personal medical advice" note.