Skip to content

Lesson 1 of 5 · 8 min

Your first REST API call

Get a brain's key, store it properly and make your first calls to the Zunous REST API with curl and Node.js, understanding every possible error.

The Zunous REST API gives access to the same things as the MCP server (role instructions, skills, knowledge with citations, memory and permissions), but with ordinary HTTP calls. It's the simplest way to integrate a brain into your backend.

What you'll achieve

  • Store the access key as a server-side secret.
  • Make your first calls with curl and with Node.js.
  • Recognize each error code and know what to do.

The key and the base address

Each brain has an access key (ck_…). An admin in your organization generates it in the Console, on the brain's page, and it's shown only once. Ask for it through a secure channel and store it as an environment variable:

bash
export ZUNOUS_LLAVE="ck_…"

Each brain's base address is:

text
https://mcp.zunous.com/api/v1/{organización}/{brain}

For example, https://mcp.zunous.com/api/v1/acme/comercial. The key works for that brain and nothing else.

Three non-negotiable rules:

  • The key goes in the Authorization: Bearer ck_… header of every call.
  • It's a server-side secret: the API doesn't send CORS headers, so it doesn't work from a browser and must not live in a mobile app.
  • It never goes in the repository. If someone rotates it, you only change the variable.

More details in Authentication and keys.

First calls with curl

The role instructions, which you can use as a system message if you call a model yourself:

bash
curl -s https://mcp.zunous.com/api/v1/acme/comercial/instrucciones \
  -H "Authorization: Bearer $ZUNOUS_LLAVE"

The brain's skills:

bash
curl -s https://mcp.zunous.com/api/v1/acme/comercial/habilidades \
  -H "Authorization: Bearer $ZUNOUS_LLAVE"

A search in the knowledge:

bash
curl -s https://mcp.zunous.com/api/v1/acme/comercial/buscar \
  -H "Authorization: Bearer $ZUNOUS_LLAVE" \
  -H "Content-Type: application/json" \
  -d '{"consulta": "discount policy", "k": 3}'

Route names and input field names are in Spanish (consulta, contenido, evento), and so are the error messages. The OpenAPI 3.1 specification is public at https://mcp.zunous.com/api/v1/openapi.json: use it to generate a client or import it into another tool.

A minimal client in Node.js

Node.js 18 or later includes fetch, so you don't need any dependencies:

javascript
const BASE = "https://mcp.zunous.com/api/v1/acme/comercial";
const LLAVE = process.env.ZUNOUS_LLAVE;

export async function zunous(ruta, cuerpo) {
  const respuesta = await fetch(BASE + ruta, {
    method: cuerpo ? "POST" : "GET",
    headers: { Authorization: `Bearer ${LLAVE}`, "Content-Type": "application/json" },
    body: cuerpo ? JSON.stringify(cuerpo) : undefined,
  });
  const json = await respuesta.json();
  if (!respuesta.ok) throw new Error(`Zunous ${respuesta.status}: ${json.error}`);
  return json;
}

const { cerebro } = await zunous("/instrucciones");
const { habilidades } = await zunous("/habilidades");
console.log(cerebro, habilidades.map((h) => h.id));

cerebro contains the brain and its version, for example comercial@0.1.0. With GET /habilidades/{id} you get a skill's step-by-step procedure, and with GET /estado, the brain's version and the status of its knowledge sources.

The errors

Every error responds with { "error": "mensaje" }, with the message in Spanish:

CodeWhenWhat to do
400Invalid JSON or a field breaks its rule; the message says which oneFix the request
401The key is missing or doesn't match that organization and brainCheck the path and ask for the current key
404The route or the skill doesn't existCheck the path
409Memory disabled, or Autonomous Mode off when reporting an eventTalk to the admin
413The body exceeds 100,000 charactersSend less data
5xxTemporary failureRetry with increasing backoff (1 s, 2 s, 4 s)

The 401 is the same whether the key is wrong or the brain doesn't exist, on purpose: that way nobody can find out which organizations or brains exist. The API has no per-minute call limit today and doesn't charge per call, but avoid loops that call it nonstop. The full reference is in REST API reference.

Practice

You work at LogiExpress Perú S.A.C., a courier company in Lima, and the admin gave you the key for the comercial brain in the logiexpress organization:

  1. Store the key in an environment variable on your machine, never in a file in the repository.
  2. Call GET /instrucciones and GET /habilidades with curl and write down the available skills.
  3. Write the minimal client in Node.js and call GET /habilidades/responder_lead_nuevo.
  4. Deliberately trigger a 401 (remove a letter from the key) and a 400 (send {"consulta": "a"} to /buscar) and read the messages.
  5. Call GET /estado to see the brain's version and its sources.

Check what you learned

1. You want to call the API from your web page's JavaScript to skip the backend. Does it work?

2. You get a 400 with the message consulta: …. What does it mean?

3. Why is the 401 the same when the key is wrong and when the brain doesn't exist?