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:
curl -X POST https://api.keysense.tech/detect \
-H "Content-Type: application/json" \
-H "X-API-Key: ks_live_..." \
-d '{"text": "руддщ цщкдв"}'{
"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.
# All requests must include this header:
X-API-Key: ks_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxPOST /detect
Detect and correct a keyboard layout error in the given text.
Base URL
https://api.keysense.techRequest body
| Field | Type | Description |
|---|---|---|
| text | string | The garbled text to correct. Max 5,000 characters. Required. |
| use_ai | boolean | Force AI verification regardless of confidence score. Default: false. Pro/Enterprise only. |
Response format
{
"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 }
]
}| Field | Description |
|---|---|
| decoded | The corrected text output. |
| layout | BCP-47 layout ID detected as the source of the error (e.g. "ru-RU"). |
| confidence | Detection confidence 0–1. Values ≥0.70 are considered reliable. |
| ai_used | Whether the Claude AI fallback was invoked for this request. |
| processing_ms | Total server-side processing time in milliseconds. |
| word_coverage | Fraction of decoded words matched against a language dictionary (0–1). |
| phrase_coverage | Fraction of consecutive word pairs matching common English bigrams (0–1). |
| keyboard_profile | Detected physical keyboard type (ANSI, ISO, JIS, compact, TKL). |
| candidates | Top alternative layout candidates with their decoded text and confidence scores. |
Errors
All errors return a JSON body with an error field.
| Status | Meaning |
|---|---|
| 400 | Bad request — missing or invalid "text" field. |
| 401 | Unauthorized — missing or invalid API key. |
| 402 | Payment required — monthly correction limit reached. Upgrade your plan. |
| 429 | Rate limited — too many requests in a short window. Slow down and retry. |
| 500 | Internal server error — unexpected failure. Contact support@keysense.tech. |
Rate limits
In addition to monthly correction limits, per-second rate limits protect service stability:
| Plan | Monthly corrections | Burst (req/sec) |
|---|---|---|
| Free | 500 | 5 |
| Pro | 50,000 | 50 |
| Enterprise | Custom | Custom |
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
npm install @keysense/sdk
# or
pnpm add @keysense/sdkBasic usage
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); // trueWith AbortSignal (timeout)
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
| Parameter | Behaviour |
|---|---|
| use_ai: false | Rule-based only. No external call. Fastest. Default. |
| use_ai: "auto" | AI invoked only when rule-based confidence <0.70. Balanced accuracy + speed. |
| use_ai: true | Always invoke AI. Highest accuracy. Adds ~200–600ms latency. Pro/Enterprise. |
Supported layouts (70+)
All layouts are detected in a single sweep. You do not need to specify the source layout.
Latency & accuracy
Latency
| Mode | Typical p50 | Notes |
|---|---|---|
| Rule-based only | <5ms | Runs entirely inside Cloudflare Workers. No external network calls. |
| AI auto mode | 5–600ms | AI invoked only when confidence <0.70 (~6% of requests). |
| AI forced | 200–600ms | Depends 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.
