Developer docs
API reference

AI · TribeMate

TribeMate is the institution AI tutor. Organisation servers call Partner AI with a partner token. Learners in Campus / widget call Ask with a verified user token. Both share one monthly prompt quota on the institution.

Base: https://www.tribepeer.com/api. Partner routes need Authorization: Bearer <partner_jwt> and scope ai:chat. Learner Ask needs a product JWT plus X-Institution-Uuid. Never put tp_sec_ in a browser.

Plans and quota

Quota counts successful completions on the institution for the current calendar month. Every AI response includes usage.

API AI add-onUnlocks Partner /ai/chat and Ask for API-built apps
CampusIncludes Ask for that school’s learners
usage.quotaMonthly prompt allowance (0 = not entitled)
usage.usedSuccessful prompts this month
usage.remainingquota − used, floored at 0

Organisation chat

POST /partner/v1/ai/chat
Scope: ai:chat

Run a tutor completion from your server. Prefer this for portals, LMS plugins, and backend-for-frontend apps.

Headers

AuthorizationBearer <access_token> from POST /partner/v1/auth/token
Content-Typeapplication/json
Acceptapplication/json

Request body

Send either a single message (optional context), or a full messages array. If messages is present and non-empty, it wins.

messagestring, max 8000Required when messages is omitted
contextstring, max 12000Optional system context (truncated server-side)
messagesarray, max 20Optional multi-turn transcript
messages[].rolesystem | user | assistantRequired with messages
messages[].contentstring, max 8000Required with messages

Example — single turn with lesson context

POST /api/partner/v1/ai/chat
curl -s https://www.tribepeer.com/api/partner/v1/ai/chat \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Explain photosynthesis in two sentences.",
    "context": "SS1 Biology · Module 2 · Leaf structure"
  }'

Example — multi-turn messages

JSON body
{
  "messages": [
    { "role": "system", "content": "You are TribeMate for Lagos High School. Be brief." },
    { "role": "user", "content": "What is a cell?" },
    { "role": "assistant", "content": "A cell is the basic unit of life." },
    { "role": "user", "content": "Give one plant-cell organelle." }
  ]
}

Success response 200

application/json
{
  "reply": "Photosynthesis converts light energy into chemical energy in plants…",
  "model": "…",
  "usage": { "quota": 2000, "used": 41, "remaining": 1959 }
}

Organisation usage

GET /partner/v1/ai/usage
Scope: ai:chat

Read the current month’s quota without spending a prompt.

GET /api/partner/v1/ai/usage
curl -s https://www.tribepeer.com/api/partner/v1/ai/usage \
  -H "Authorization: Bearer $TOKEN"

Success response 200

application/json
{
  "usage": { "quota": 2000, "used": 41, "remaining": 1959 },
  "enabled": true
}

enabled is false when the platform AI client is not configured.

Learner Ask (Campus / widget)

POST /product/v1/ai/ask

Verified human asks TribeMate. Counts against the same monthly quota.

Headers

AuthorizationBearer <product_jwt> — after email verification
X-Institution-UuidRequired
Content-Typeapplication/json

Request body

messagestring, required, max 4000The learner’s question
POST /api/product/v1/ai/ask
curl -s https://www.tribepeer.com/api/product/v1/ai/ask \
  -H "Authorization: Bearer $USER_TOKEN" \
  -H "X-Institution-Uuid: $INSTITUTION_UUID" \
  -H "Content-Type: application/json" \
  -d '{ "message": "What is osmosis?" }'

Success response 200

application/json
{
  "reply": "Osmosis is the movement of water across a semi-permeable membrane…",
  "usage": { "quota": 2000, "used": 42, "remaining": 1958 }
}

Errors

401Missing / invalid JWT
403Missing ai:chat (Partner) or unverified user (product)
402api_ai_required or ai_quota_exceeded (includes usage)
422Validation
429Rate limit
ai_disabledPlatform model offline / not configured
402 · quota
{
  "error": "ai_quota_exceeded",
  "message": "This institution has used its AI prompts for the month.",
  "usage": { "quota": 2000, "used": 2000, "remaining": 0 }
}

Best practices

Embed AI Chat Organisation API Learner API API plans