{"openapi":"3.1.0","info":{"title":"Card Doctor service","version":"1.0.0","description":"Checks flash cards (free), repairs them with an AI model running on Cloudflare Workers AI and makes audio recordings (key or trial). Card text is never logged. Text sent for checking or a rewrite is not stored. Text sent for a recording is held by our voice service until the recording is made, and the recording is deleted within 7 days (usually a day)."},"servers":[{"url":"https://carddoctor.vibefrontier.com/api/v1"}],"components":{"securitySchemes":{"key":{"type":"http","scheme":"bearer","description":"Card Doctor Pro key, cd_..."},"trial":{"type":"apiKey","in":"header","name":"X-Card-Doctor-Install","description":"A random UUID v4 the installation keeps; 20 uses in total."}},"schemas":{"Error":{"type":"object","required":["error","message"],"properties":{"error":{"type":"string"},"message":{"type":"string"}}},"Card":{"type":"object","additionalProperties":false,"properties":{"kind":{"type":"string","enum":["basic","cloze"],"default":"basic"},"question":{"type":"string","maxLength":2000},"answer":{"type":"string","maxLength":2000},"cloze":{"type":"string","maxLength":4000},"cloze_number":{"type":"integer","minimum":1,"default":1},"question_media":{"type":"boolean"},"answer_media":{"type":"boolean"},"media_key":{"type":"string"}}},"AudioJob":{"type":"object","required":["job","retry_after"],"properties":{"job":{"type":"string","pattern":"^[0-9a-f]{32}$"},"retry_after":{"type":"integer","description":"Seconds to wait before asking again (also the Retry-After header)."}}},"Finding":{"type":"object","required":["rule","title","level","message","why","fix","related"],"properties":{"rule":{"type":"string"},"title":{"type":"string"},"level":{"type":"integer","enum":[1,2,3],"description":"3 breaks the card, 2 weakens it, 1 is worth a look."},"message":{"type":"string"},"why":{"type":"string"},"fix":{"type":"string"},"related":{"type":"array","items":{"type":"string"},"description":"Ids of the other cards involved."}}},"FixedCard":{"type":"object","description":"{question, answer} for a basic card, {cloze} for a cloze card.","properties":{"question":{"type":"string"},"answer":{"type":"string"},"cloze":{"type":"string"}}}}},"paths":{"/check":{"post":{"operationId":"checkCards","summary":"Check cards (free, no key; 120 requests per hour per address)","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["cards"],"properties":{"cards":{"type":"array","minItems":1,"maxItems":200,"items":{"type":"object","required":["id","card"],"properties":{"id":{"type":"string","maxLength":64},"card":{"$ref":"#/components/schemas/Card"}}}},"options":{"type":"object","properties":{"long_answer_words":{"type":"integer","default":25},"cloze_max_gaps":{"type":"integer","default":3},"cloze_max_gap_words":{"type":"integer","default":10}}}}}}}},"responses":{"200":{"description":"Findings per card","content":{"application/json":{"schema":{"type":"object","properties":{"results":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"findings":{"type":"array","items":{"$ref":"#/components/schemas/Finding"}}}}}}}}}},"400":{"description":"Invalid body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"413":{"description":"Body over 256 KB","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limited","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/fix":{"post":{"operationId":"fixCard","summary":"Rewrite a flawed card into one to four clean cards","security":[{"key":[]},{"trial":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["card"],"properties":{"card":{"$ref":"#/components/schemas/Card"},"language":{"type":"string","default":"en"}}}}}},"responses":{"200":{"description":"The rewrite (empty cards when there is nothing to fix)","content":{"application/json":{"schema":{"type":"object","properties":{"cards":{"type":"array","maxItems":3,"items":{"$ref":"#/components/schemas/FixedCard"}},"note":{"type":"string"},"trial_left":{"type":"integer","description":"Trial callers only."}}}}}},"400":{"description":"Invalid body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"invalid_key (a key that matches nothing) or unauthorized (no credentials)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"402":{"description":"inactive or trial_used","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"fair_use, or too_many (today's repair budget for this account or network)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"502":{"description":"no_clean_fix: nothing counted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"busy (nothing counted) or capacity (the service-wide daily budget is used up)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/audio":{"post":{"operationId":"makeAudio","summary":"Make an MP3 recording of up to 300 characters (UTF-16 code units: an emoji is 2); the audio, or a job to collect","description":"Recordings are made by our own voice service and can wait in a queue for minutes or hours: the answer is 200 with the MP3 when it is ready, else 202 with a job to collect with GET /audio/{job}. The same caller asking for the same text and language again reuses the job. One use is counted when the audio is first delivered. Card text is never logged. Text sent for checking or a rewrite is not stored. Text sent for a recording is held by our voice service until the recording is made, and the recording is deleted within 7 days (usually a day).","security":[{"key":[]},{"trial":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["text"],"properties":{"text":{"type":"string","description":"At most 300 UTF-16 code units (JavaScript string length; characters outside the Basic Multilingual Plane count 2)."},"language":{"type":"string","default":"en","description":"A language tag from the voice list (en, en-GB and es by default): the exact tag is tried first, then its primary subtag. Anything else is 400 unsupported_language, listing the supported ones."}}}}}},"responses":{"200":{"description":"MP3 audio, ready","content":{"audio/mpeg":{"schema":{"type":"string","format":"binary"}}}},"202":{"description":"Not ready: collect it with GET /audio/{job} after retry_after seconds","headers":{"Retry-After":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AudioJob"}}}},"400":{"description":"Invalid body, or unsupported_language (the message and `languages` list the supported ones)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"invalid_key (a key that matches nothing) or unauthorized (no credentials)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"402":{"description":"inactive or trial_used","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"fair_use, too_many (today's audio budget for this account or network) or too_many_pending (20 jobs already wait)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"busy (the voice service is busy; retry_after seconds; nothing counted), capacity (the service-wide daily budget is used up) or not_available (speech is switched off)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/audio/{job}":{"get":{"operationId":"getAudio","summary":"Collect a recording: the MP3, or the same 202 until it is ready","description":"Only the caller that made the job can read it. The first delivery counts one use; fetching the same job again counts nothing. Jobs end after 24 hours.","security":[{"key":[]},{"trial":[]}],"parameters":[{"name":"job","in":"path","required":true,"schema":{"type":"string","pattern":"^[0-9a-f]{32}$"}}],"responses":{"200":{"description":"MP3 audio","content":{"audio/mpeg":{"schema":{"type":"string","format":"binary"}}}},"202":{"description":"Not ready yet","headers":{"Retry-After":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AudioJob"}}}},"401":{"description":"invalid_key or unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"402":{"description":"inactive or trial_used","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"not_found: no such job for this caller, or it expired","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"fair_use","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"502":{"description":"audio_failed: the voice service could not make it; nothing counted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"busy or not_available","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/checkout":{"post":{"operationId":"startCheckout","summary":"Start a purchase (Card Doctor Pro subscription, or the one-time ChatDeck Pro); the person opens the URL","security":[{},{"key":[]}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"claim":{"type":"string","pattern":"^[0-9a-f]{64}$","description":"sha256 hex of a secret you keep; use it with /claim. Not accepted together with a key."},"product":{"type":"string","enum":["card-doctor-pro","chatdeck-pro"],"default":"card-doctor-pro","description":"chatdeck-pro is a one-time $5.00 payment. With a valid key in Authorization the purchase is added to that key's account (no new key, no claim)."}}}}}},"responses":{"200":{"description":"Stripe Checkout URL","content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string"}}}}}},"400":{"description":"bad_request (unknown product, or a claim together with a key) or invalid_claim","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"invalid_key (the key sent matches nothing)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"claim_used, or already_owned (this account has ChatDeck Pro)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limited","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/claim":{"post":{"operationId":"claimKey","summary":"Collect the key of a paid checkout, once","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["secret"],"properties":{"secret":{"type":"string"}}}}}},"responses":{"200":{"description":"The key, shown once","content":{"application/json":{"schema":{"type":"object","properties":{"key":{"type":"string"}}}}}},"404":{"description":"pending: not paid yet","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"410":{"description":"claimed or expired","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limited","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/account":{"get":{"operationId":"account","summary":"Plan, status and usage","security":[{"key":[]},{"trial":[]}],"responses":{"200":{"description":"Account","content":{"application/json":{"schema":{"type":"object","properties":{"plan":{"type":"string","enum":["pro","trial","none"],"description":"none: a valid key whose account only bought a one-time product (no subscription); /fix, /audio and /occlusion answer 402 inactive for it."},"status":{"type":"string"},"entitlements":{"type":"object","properties":{"chatdeck":{"type":"boolean","description":"ChatDeck Pro was bought and not fully refunded."}}},"active":{"type":"boolean","description":"Whether Pro (or the trial) can be used right now: the same test that gates /fix. A subscription whose period ended more than 7 days ago is not active even if its status says so."},"fixes_this_month":{"type":["integer","null"]},"audio_this_month":{"type":["integer","null"]},"trial_left":{"type":["integer","null"]},"features":{"type":"object","description":"Usage this month per metered feature; limit and remaining are null on Pro.","additionalProperties":{"type":"object","properties":{"used":{"type":"integer"},"limit":{"type":["integer","null"]},"remaining":{"type":["integer","null"]}}}}}}}}},"401":{"description":"invalid_key (a key that matches nothing) or unauthorized (no credentials)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/occlusion":{"post":{"operationId":"detectOcclusion","summary":"Find label boxes on a diagram (PNG in, boxes out); counts one use, key or install id","description":"Content-Length is required and at most 4,194,304 bytes. The picture is forwarded to the detector and never stored. Every response carries an X-Source header with the address where the source code of the detector is offered.","security":[{"key":[]},{"trial":[]}],"requestBody":{"required":true,"content":{"image/png":{"schema":{"type":"string","format":"binary"}}}},"responses":{"200":{"description":"Boxes in pixels of the picture, with the plan and usage","content":{"application/json":{"schema":{"type":"object","required":["width","height","boxes","plan","used","limit","remaining","period_ends"],"properties":{"width":{"type":"number"},"height":{"type":"number"},"boxes":{"type":"array","maxItems":500,"items":{"type":"object","required":["x","y","width","height"],"properties":{"x":{"type":"number"},"y":{"type":"number"},"width":{"type":"number"},"height":{"type":"number"},"text":{"type":"string","maxLength":300,"description":"What the label reads, when the detector read it."}}}},"plan":{"type":"string","enum":["pro","free"]},"used":{"type":"integer"},"limit":{"type":["integer","null"],"description":"null on Pro."},"remaining":{"type":["integer","null"],"description":"null on Pro."},"period_ends":{"type":"string","format":"date-time"}}}}}},"401":{"description":"invalid_key (a key that matches nothing) or unauthorized (no key and no install id)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"402":{"description":"inactive (known key, no active subscription) or limit_reached (adds used, limit, remaining, period_ends)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"413":{"description":"too_large: no Content-Length, or over the limit","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"415":{"description":"not_png","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"fair_use (beyond the Pro monthly limit) or too_many (this network's or this Pro account's detections for the day)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"503":{"description":"busy (the detector failed; the use is not counted) or capacity (the day's detection capacity is used up)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/portal":{"post":{"operationId":"billingPortal","summary":"Stripe billing portal URL","security":[{"key":[]}],"responses":{"200":{"description":"URL","content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string"}}}}}},"401":{"description":"invalid_key (a key that matches nothing) or unauthorized (no credentials)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"not_found: the account has no subscription to manage (only a one-time purchase)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/key/rotate":{"post":{"operationId":"rotateKey","summary":"Issue a new key; the old one stops working","security":[{"key":[]}],"responses":{"200":{"description":"The new key, shown once","content":{"application/json":{"schema":{"type":"object","properties":{"key":{"type":"string"}}}}}},"401":{"description":"invalid_key (a key that matches nothing) or unauthorized (no credentials)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}