POST
/
trpc
/
data.context
Get Context
curl --request POST \
  --url https://api.kontext.dev/trpc/data.context \
  --header 'x-api-key: <x-api-key>'

Overview

  • Recommended via SDK: Persona.getContext({ userId, task, userQuery? }).
  • This tRPC endpoint powers the same call.

Authentication

x-api-key
string
required
Your API key from the Kontext dashboard

Request (tRPC HTTP)

Body (JSON): { "input": { userId, task, userQuery?, maxFacts?, cachePolicy?, includeRecentData? } }
  • userId (string, required): OAuth‑connected user for your developer
  • task (string, required): e.g., chat, email, support, writing
  • userQuery (string, optional): per‑turn user message to bias retrieval/reranking for this call only
  • maxFacts (number, optional): upper bound on facts considered
  • cachePolicy ('cached'|'fresh'|'fallback', optional, default cached)
  • includeRecentData (boolean, optional, default true)

Response (tRPC envelope)

200 OK
{
  "result": {
    "data": {
      "systemPrompt": "string",
      "dataSources": [
        { "text": "string", "metadata": { "source": "gmail", "timestamp": "..." } }
      ],
      "metadata": {
        "factCount": 23,
        "generatedAt": "2024-01-15T14:30:00Z",
        "cacheHit": false,
        "processingTimeMs": 120,
        "ttlSeconds": 300
      }
    }
  }
}
Note: If you use the SDK or a tRPC client, you receive the inner object directly (no tRPC wrapper).

Notes

  • userQuery (per‑turn personalization): Passing userQuery focuses retrieval and reranks facts for this specific call. It does not mutate stored facts; it only biases selection/ordering for the current turn.
  • Privacy (fixed server‑side): Privacy level is enforced on the server and cannot be changed by clients. The server uses DEFAULT_PRIVACY_LEVEL (env; default strict).

Errors

  • 401 UNAUTHORIZED — invalid API key
  • 403 FORBIDDEN — user lacks OAuth access
  • 400 BAD_REQUEST — invalid payload
  • 500 INTERNAL_SERVER_ERROR

Examples

curl -X POST https://api.kontext.dev/trpc/data.context \
  -H "x-api-key: ktext_abc123..." \
  -H "content-type: application/json" \
  -d '{
    "input": {
      "userId": "user_abc123",
      "task": "chat",
      "userQuery": "summarize recent emails about the Q4 launch",
      "maxFacts": 50,
      "cachePolicy": "fallback",
      "includeRecentData": true
    }
  }'

Rate Limiting

  • ~30 req/min per API key (burst ~5 rps)
  • Headers: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset