# Tarot draw plus an AI-written reading, across two hosts

> The draw and the reading are separate services. The calculation API picks the cards - deterministically, if you give it a seed - and the chat API writes a short reading of the cards you send it. Keeping them apart means the cards a user saw are always the cards that were interpreted.

Source: https://astronode.dev/recipes/tarot-reading-ai-interpretation · Updated: 2026-12-01

**What you build:** A three-card reading whose cards can be redrawn from a stored seed, with an AI-written interpretation. (Node.js, Python)

## Two hosts, one key

| Step | Host | Endpoint | Plan |
| --- | --- | --- | --- |
| Draw | `api.astronode.dev` | [`POST /v1/tarot/draw`](https://astronode.dev/capabilities/tarot/tarot-draw) | Free |
| Read | `chatbot-api.astronode.dev` | [`POST /v1/tarot/interpret`](https://astronode.dev/capabilities/tarot/tarot-interpret) | Free |

The same API key authenticates on both hosts. The interpret endpoint is documented, but it is not in the public playground: every call runs a language model. On the Free plan it is limited by the normal per-minute window and monthly quota only - the 5-messages-a-day cap applies to the chat endpoints, not to tarot.

## Node: draw, map, interpret

```javascript
// tarot.mjs - Node 18+, server-side. One key works on both hosts.
const API = "https://api.astronode.dev"; // calculation API: the draw
const CHAT = "https://chatbot-api.astronode.dev"; // chat API: the AI reading
const headers = { authorization: `Bearer ${process.env.ASTRONODE_API_KEY}`, "content-type": "application/json" };

const question = "Should I take the new job offer?";
// Persist the seed with the reading: the same seed redraws the same cards.
const seed = "reading-7731";

// 1. Draw three cards (deterministic for a given seed).
const drawRes = await fetch(`${API}/v1/tarot/draw`, {
  method: "POST",
  headers,
  body: JSON.stringify({ spread: "three_card", seed }),
});
const draw = (await drawRes.json()).data;

// 2. Map the draw onto the interpret schema: <= 10 cards, <= 8 keywords each.
const cards = draw.cards.map((c) => ({
  position: c.position.label,
  name: c.card.name,
  orientation: c.orientation,
  keywords: c.meaning.keywords.slice(0, 8),
}));
console.log(cards.map((c) => `${c.position}: ${c.name} (${c.orientation})`).join(" | "));

// 3. Ask the chat host for a written reading of exactly these cards.
const readRes = await fetch(`${CHAT}/v1/tarot/interpret`, {
  method: "POST",
  headers,
  body: JSON.stringify({ spread_label: "Past / Present / Future", question, cards }),
});
const reading = await readRes.json();
if (!readRes.ok) throw new Error(`${readRes.status} ${reading.error.code}`);
console.log(readRes.status, reading.request_id, `${reading.interpretation.length} chars`);
```

```text
$ node tarot.mjs
Past: The High Priestess (reversed) | Present: The Moon (upright) | Future: King of Pentacles (upright)
200 req_01M8S694160F9D9MF6BWJXK9NN 667 chars
```

The mapping step is where integrations break. `/v1/tarot/draw` returns rich objects (`position.label`, `card.name`, `meaning.keywords`, the upright and reversed texts); `/v1/tarot/interpret` accepts only `position`, `name`, `orientation` and up to 8 `keywords` per card, at most 10 cards, a `spread_label` up to 80 characters and a `question` up to 300. Any extra field is a `400 VALIDATION_ERROR` - the body is strict - so build the object explicitly as above rather than spreading the draw into it.

The interpret response shape. In our run the text came from the harness's stub model, so it is not quoted; in production `interpretation` is the model's plain-text reading.

```json
{
  "success": true,
  "request_id": "req_…",
  "interpretation": "<plain text, a few short paragraphs>"
}
```

## Python: store the seed, not the cards

Without `seed`, the API picks one and returns it. Save that string with the reading and you can redraw the identical spread later - for a history screen, a share link or a support ticket - instead of storing ten card objects.

```python
# tarot_seed.py - Python 3.9+, standard library only.
import json, os, urllib.request

API = "https://api.astronode.dev"
KEY = os.environ["ASTRONODE_API_KEY"]

def draw(spread, seed=None):
    body = {"spread": spread}
    if seed:
        body["seed"] = seed
    req = urllib.request.Request(
        API + "/v1/tarot/draw",
        data=json.dumps(body).encode(),
        headers={"Authorization": "Bearer " + KEY, "Content-Type": "application/json"},
    )
    return json.load(urllib.request.urlopen(req))["data"]

first = draw("celtic_cross")            # no seed: the API picks one
seed = first["seed"]                     # store it next to the reading
again = draw("celtic_cross", seed)       # replaying the stored seed
names = lambda d: [(c["card"]["id"], c["orientation"]) for c in d["cards"]]
print(len(first["cards"]), "cards, seed", seed[:8] + "...")
print("same cards on replay:", names(first) == names(again))
```

The seed differs on every run; the replay check does not.

```text
$ python3 tarot_seed.py
10 cards, seed 812cad49...
same cards on replay: True
```

## Things to decide before launch

- **Draw first, then ask.** If the question changes, keep the seed and the cards; send only the new `question` to the interpret call. Redrawing because the wording changed makes the draw feel rigged.
- **Model output is not deterministic.** The same cards and question can produce a differently worded reading. If users can revisit a reading, store the returned text.
- **Plan for 502 and 504.** The interpret call depends on a language-model provider; it can fail with `LLM_PROVIDER_ERROR` (502) or `LLM_TIMEOUT` (504) even when everything else is healthy. Show the cards and the meanings from the draw, and offer a retry for the written reading.
- **Card meanings are already in the draw.** Each card carries a headline, upright and reversed texts and a `source`; the draw alone is a complete, model-free reading for users on a tight quota.

## Questions

**What do I end up with?**

A three-card reading whose cards can be redrawn from a stored seed, with an AI-written interpretation. The code is in Node.js and Python.

**Which endpoints does this recipe call, and in what order?**

2 endpoints, in this order: Tarot Card Draw (`POST /v1/tarot/draw`), then AI Tarot Interpretation (`POST /v1/tarot/interpret`).

## Endpoints, in call order

- [`POST /v1/tarot/draw`](https://astronode.dev/capabilities/tarot/tarot-draw) - Tarot Card Draw API
- [`POST /v1/tarot/interpret`](https://astronode.dev/capabilities/tarot/tarot-interpret) - AI Tarot Interpretation API
