Building a Study Bot

End-to-end tutorial β€” create a Korean study bot that chats, manages flashcards, and tracks progress.

4 min read

This guide walks through building a complete Korean study bot using the Chamelingo API. By the end, your bot will:

  1. Chat with the AI tutor
  2. Create flashcard decks from conversations
  3. Review cards using spaced repetition
  4. Track learning progress

Prerequisites#

Create an API key with scopes: tutor, decks, progress.

bash
curl -X POST https://api.chamelingo.com/api/v1/keys \
  -H "Cookie: better-auth.session_token=YOUR_SESSION" \
  -H "Content-Type: application/json" \
  -d '{"name": "Study Bot", "scopes": ["tutor", "decks", "progress"]}'

Step 1: Chat with the Tutor#

Ask the tutor to teach vocabulary on a topic:

bash
curl -N -X POST https://api.chamelingo.com/api/v1/chat \
  -H "Authorization: Bearer ck_live_YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{"message": "Teach me 5 Korean words for ordering food at a restaurant"}'

Parse the SSE stream and save the conversation_id from the done event.

Step 2: Create a Flashcard Deck#

bash
curl -X POST https://api.chamelingo.com/api/v1/decks \
  -H "Authorization: Bearer ck_live_YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: food-deck-v1" \
  -d '{"title": "Restaurant Korean", "description": "Food ordering vocabulary"}'

Step 3: Import Cards#

Extract vocabulary from the tutor's response and import them:

bash
curl -X POST https://api.chamelingo.com/api/v1/decks/DECK_ID/cards/import \
  -H "Authorization: Bearer ck_live_YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: food-import-v1" \
  -d '{
    "cards": [
      {"front": "메뉴", "back": "Menu", "phonetic": "menyu", "tags": ["food"]},
      {"front": "μ£Όλ¬Έν•˜λ‹€", "back": "To order", "phonetic": "jumunhada", "tags": ["food"]},
      {"front": "κ³„μ‚°μ„œ", "back": "Bill/Check", "phonetic": "gyesanseo", "tags": ["food"]},
      {"front": "λ§›μžˆλ‹€", "back": "Delicious", "phonetic": "masitda", "tags": ["food"]},
      {"front": "λ¬Ό", "back": "Water", "phonetic": "mul", "tags": ["food"]}
    ]
  }'

Step 4: Review Due Cards#

Check which cards are due for review:

bash
curl "https://api.chamelingo.com/api/v1/decks/DECK_ID/cards/review?limit=10" \
  -H "Authorization: Bearer ck_live_YOUR_KEY_HERE"

Step 5: Submit Review Results#

After the user reviews cards, submit their ratings:

bash
curl -X POST https://api.chamelingo.com/api/v1/reviews \
  -H "Authorization: Bearer ck_live_YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{
    "results": [
      {"card_id": "card_abc", "rating": 3},
      {"card_id": "card_def", "rating": 4},
      {"card_id": "card_ghi", "rating": 1}
    ]
  }'

Ratings follow the FSRS-5 scale: 1 = Again, 2 = Hard, 3 = Good, 4 = Easy.

Step 6: Track Progress#

bash
curl https://api.chamelingo.com/api/v1/progress/summary \
  -H "Authorization: Bearer ck_live_YOUR_KEY_HERE"

The response includes XP, level, current streak, hearts, and overall stats β€” everything your bot needs to show learning progress.

Putting It Together#

A typical study session flow:

  1. GET /progress/summary β€” show the user their stats
  2. GET /decks β€” list their decks
  3. GET /decks/:id/cards/review β€” get due cards
  4. Present cards to the user, collect ratings
  5. POST /reviews β€” submit results
  6. POST /chat β€” ask the tutor for help on missed words
  7. Repeat daily
Tip

Use the Idempotency-Key header on all POST requests to safely handle retries. If your bot crashes mid-import, replaying the same request won't create duplicates.