Alberei Documentation · v1

Build with Alberei

Alberei is a modular humour engine accessible over a small REST surface. This document is everything an integrator needs to ship: methodology, integration patterns for the most common product shapes, safety semantics, and downloadable guides.

Quickstart

One endpoint, one token. Send a context and get back items.

curl -X POST https://api.llulllab.com/alberei/v1/generate \
  -H "Content-Type: application/json" \
  -H "X-Api-Token: YOUR_TOKEN" \
  -d '{"lang":"en","context":"a robot apologising for being late","count":3,"register":"warm"}'

The full request and response shape lives in the API reference.

Methodology

Alberei treats humour as a combinatorial problem across three orthogonal axes: register, structure, and cultural frame. A request specifies the first; the engine selects the second and third per language.

Register

The voice. Four named registers in v1: wry, absurd, deadpan, warm. Picking a register is a product decision, not a generation parameter to be tuned per call. A wellbeing companion will likely stay in warm; a sarcastic productivity assistant will stay in wry.

Structure

The mechanism by which an item lands. The public taxonomy returned in items[].structure:

  • misdirection: the second clause reframes the first
  • literal-overshoot: a metaphor taken too far on purpose
  • self-deprecation: the speaker is the target
  • juxtaposition: incongruous pairing in one frame
  • anticlimax: promised escalation, delivered deflation
  • escalation: momentum carried past sense
  • deflation: the expected payoff withheld
  • surreal-shift: local logic broken without warning
  • deadpan-statement: no flag that humour is happening
  • warm-twist: kindness reframes apparent slight

Cultural frame

Each language generates with its own cultural framing. Bengali humour is not English humour translated; Japanese deadpan is not English deadpan with a different surface. Frames are not exposed as parameters; the engine selects them based on lang.

The public taxonomy is stable across v1. Additive expansion is non-breaking and will be announced in the changelog.

Use cases

Embodied agents and social robots

Trigger Alberei in the conversational loop when a context invites colour: a routine apology, an idle moment, an answer to a small-talk cue. Pick warm or deadpan depending on the persona. Cache nothing per user; humour that repeats stops being humour.

Voice assistants and smart speakers

Generate ahead of TTS so latency lands inside the speech-synthesis budget. Prefer short length for spoken delivery. Use audience as a per-household tag so analytics can compare register receptions without sending PII.

Customer-service chatbots

Use Alberei selectively. A humour line in a refund flow can derail trust; a humour line in a delivery-status flow can soften a wait. Gate on context classifier, not on every turn.

Game NPC dialogue

Pre-generate batches per quest beat and cache by (lang, register, beat_id). Sample at runtime. Refresh the cache when content updates.

Writing assistants and content tools

Surface Alberei as an "add humour" command operating on the selected paragraph. Show all count items so the author chooses. Always show the structure tag in the editor sidebar so the author can ask for a different mechanism.

Inaugural pilot. Phi-Yo Embodied, Llull Lab's wellbeing companion robot, uses Alberei as its humour module. The integration uses the warm register and short length, with a per-session cap to keep humour scarce and intentional.

Integration patterns

JavaScript (Node, browser)

const r = await fetch('https://api.llulllab.com/alberei/v1/generate', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', 'X-Api-Token': process.env.ALBEREI_TOKEN },
  body: JSON.stringify({ lang: 'en', context, count: 3, register: 'wry' })
});
const data = await r.json();
const item = data.items[Math.floor(Math.random() * data.items.length)];

Python

import os, requests
r = requests.post(
  'https://api.llulllab.com/alberei/v1/generate',
  headers={'X-Api-Token': os.environ['ALBEREI_TOKEN'], 'Content-Type': 'application/json'},
  json={'lang': 'en', 'context': context, 'count': 3, 'register': 'wry'},
  timeout=10
)
items = r.json()['items']

Embodied agent SDK pattern (pseudo)

on_idle_or_greeting(ctx):
  if ctx.user_signal == 'small_talk' or ctx.silence_ms > 1500:
    items = alberei.generate(lang=ctx.lang, context=ctx.summary(),
                              register='warm', length='short', count=2)
    speak(items[0].text)
    log_humour(ctx.session_id, items[0].id, items[0].structure)

Quota awareness

For dashboards and pre-flight checks, query GET /alberei/v1/usage with the same X-Api-Token header. The response returns monthly_remaining, daily_remaining, burst_remaining_per_minute, and the active monthly window. Generation responses already echo the per-call remaining counters in X-RateLimit-* headers; use the dedicated endpoint when you need quota without making a billed call.

Caching

Do not cache per user-facing utterance; repetition kills the effect. Caching by abstract beat (NPC quest beats, marketing copy slots) is fine. Cache key should include lang, register, and a deterministic context hash.

Fallback

On 503 upstream_unreachable or any 5xx, fall back to silence or to a generic non-humorous reply. Never ship a placeholder humour line that exposes that the engine failed.

Usage endpoint

Query a token's current quota state without spending a call. Returns tier, monthly quota and remaining, daily remaining, per-minute burst remaining, and the active monthly window. GET and POST are both accepted.

curl https://api.llulllab.com/alberei/v1/usage \
  -H "X-Api-Token: YOUR_TOKEN"

Full field list and status codes in the API reference.

Safety and refusal

The engine refuses contexts involving hate-speech targets, sexual content involving minors, impersonation of identifiable living individuals, and instructions to deceive humans about the bot's nature. Refusal returns HTTP 422 with body:

{"error": "unsafe_context", "message": "This context cannot be processed."}

The response is intentionally neutral. Do not surface details to end users; treat the response as a generic refusal and proceed without humour for that turn.

Downloads

Contact

Access requests and integration questions: api@alberei.de.

Llull Lab, Paris. llulllab.com.