KeySense AIKeySense AI

KeySense AI — API Reference

KeySense AI detects keyboard layout errors and corrects them in milliseconds. The API accepts garbled text and returns the corrected version along with the detected layout.

Quick start

Send your first correction request in seconds:

bash
curl -X POST https://api.keysense.tech/detect \
  -H "Content-Type: application/json" \
  -H "X-API-Key: ks_live_..." \
  -d '{"text": "руддщ цщкдв"}'
json
{
  "decoded":       "hello world",
  "layout":        "ru-RU",
  "confidence":    0.97,
  "ai_used":       false,
  "processing_ms": 1
}

Authentication

All requests require an API key. Pass it in the X-API-Key header. You can generate keys from your dashboard.

bash
# All requests must include this header:
X-API-Key: ks_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Keep your key secret. Never expose it in client-side code or public repositories. Rotate it immediately from your dashboard if it is compromised.

POST /detect

Detect and correct a keyboard layout error in the given text.

Base URL

text
https://api.keysense.tech

Request body

FieldTypeDescription
textstringThe garbled text to correct. Max 5,000 characters. Required.
use_aibooleanForce AI verification regardless of confidence score. Default: false. Pro/Enterprise only.

Response format

json
{
  "decoded":          "hello world",
  "layout":           "ru-RU",
  "confidence":       0.97,
  "ai_used":          false,
  "processing_ms":    1,
  "word_coverage":    1.0,
  "phrase_coverage":  1.0,
  "keyboard_profile": { "profile": "ansi-104", "confidence": 0.85 },
  "candidates": [
    { "layout": "ru-RU",  "text": "hello world", "confidence": 0.97 },
    { "layout": "uk-UA",  "text": "hello world", "confidence": 0.89 }
  ]
}
FieldDescription
decodedThe corrected text output.
layoutBCP-47 layout ID detected as the source of the error (e.g. "ru-RU").
confidenceDetection confidence 0–1. Values ≥0.70 are considered reliable.
ai_usedWhether the Claude AI fallback was invoked for this request.
processing_msTotal server-side processing time in milliseconds.
word_coverageFraction of decoded words matched against a language dictionary (0–1).
phrase_coverageFraction of consecutive word pairs matching common English bigrams (0–1).
keyboard_profileDetected physical keyboard type (ANSI, ISO, JIS, compact, TKL).
candidatesTop alternative layout candidates with their decoded text and confidence scores.

Errors

All errors return a JSON body with an error field.

StatusMeaning
400Bad request — missing or invalid "text" field.
401Unauthorized — missing or invalid API key.
402Payment required — monthly correction limit reached. Upgrade your plan.
429Rate limited — too many requests in a short window. Slow down and retry.
500Internal server error — unexpected failure. Contact support@keysense.tech.

Rate limits

In addition to monthly correction limits, per-second rate limits protect service stability:

PlanMonthly correctionsBurst (req/sec)
Free5005
Pro50,00050
EnterpriseCustomCustom

When rate limited you will receive a 429 response. Implement exponential back-off with jitter — the SDK does this automatically.

TypeScript / JavaScript SDK

The official SDK wraps the API with full TypeScript types, retry/backoff, and AbortSignal support.

Install

bash
npm install @keysense/sdk
# or
pnpm add @keysense/sdk

Basic usage

typescript
import { KeySenseClient } from '@keysense/sdk';

const ks = new KeySenseClient({
  apiKey: process.env.KEYSENSE_API_KEY!,
  // apiUrl defaults to https://api.keysense.tech
});

// Basic correction
const result = await ks.detect('руддщ цщкдв');
console.log(result.decoded);     // "hello world"
console.log(result.layout);      // "ru-RU"
console.log(result.confidence);  // 0.97

// With AI fallback forced
const aiResult = await ks.detect('ηεββο ςορβδ', { useAI: true });
console.log(aiResult.decoded);   // "hello world"
console.log(aiResult.ai_used);   // true

With AbortSignal (timeout)

typescript
const controller = new AbortController();
setTimeout(() => controller.abort(), 3000); // 3s timeout

const result = await ks.detect('руддщ', {
  signal: controller.signal,
});

AI fallback

By default, KeySense AI uses a purely rule-based pipeline that requires no external calls. 94% of corrections complete in under 5ms without AI.

When rule-based confidence is below 0.70, the engine can automatically call the Claude AI model for a more accurate result. This is the "auto" mode.

Controlling AI use

ParameterBehaviour
use_ai: falseRule-based only. No external call. Fastest. Default.
use_ai: "auto"AI invoked only when rule-based confidence <0.70. Balanced accuracy + speed.
use_ai: trueAlways invoke AI. Highest accuracy. Adds ~200–600ms latency. Pro/Enterprise.
Enterprise: AI processing can be disabled globally for your account. Contact enterprise@keysense.tech to enable an on-premise deployment with no external AI calls.

Supported layouts (70+)

All layouts are detected in a single sweep. You do not need to specify the source layout.

Latin — US variantsen-US, en-US-dvorak, en-US-colemak, en-US-colemak-dh, en-US-workman
Latin — Western Europeen-GB, de-DE, de-CH, de-AT, fr-FR, fr-BE, fr-CA, fr-CH, es-ES, es-419, it-IT, pt-PT, pt-BR, nl-NL, nl-BE
Latin — Nordicsv-SE, nb-NO, da-DK, fi-FI, is-IS
Latin — Eastern Europepl-PL, cs-CZ, sk-SK, ro-RO, hu-HU, lv-LV, lt-LT, et-EE, hr-HR, sl-SI, bs-BA, sq-AL, sr-RS-latin
Latin — Turkishtr-TR (QWERTY), tr-TR-f (F-layout)
Cyrillicru-RU, ru-RU-phonetic, uk-UA, uk-UA-phonetic, be-BY, bg-BG, sr-RS, mk-MK, kk-KZ, ky-KG, mn-MN
RTLar-SA, he-IL, fa-IR
Greekel-GR
CJK / Asianko-KR, ja-JP, zh-TW, th-TH, vi-VN
Otherhy-AM (Armenian), ka-GE (Georgian)

Latency & accuracy

Latency

ModeTypical p50Notes
Rule-based only<5msRuns entirely inside Cloudflare Workers. No external network calls.
AI auto mode5–600msAI invoked only when confidence <0.70 (~6% of requests).
AI forced200–600msDepends on Claude API latency. Adds network round-trip to Anthropic.

Accuracy methodology

The 94% figure refers to the fraction of real-world correction requests where the rule-based engine achieves a confidence score of ≥0.70 without invoking AI. It was measured against a mixed corpus of intentionally mis-typed English text across the top 20 supported layouts.

Confidence is calculated by a weighted scoring function that considers character coverage, vowel ratio, common bigrams, language dictionary coverage, and physical keyboard profile compatibility. A confidence of ≥0.70 is our threshold for a reliable correction.