{
  "openapi": "3.0.3",
  "info": {
    "title": "All The Words API",
    "description": "Word finder API for Wordle, Scrabble, crossword puzzles, and anagram solving.\nSupports 60+ languages with pattern matching, anagram solving, and dictionary statistics.\n\n**Features:**\n- Pattern matching with wildcards (`?` and `*`)\n- Anagram solving with blank tile support (`_` and `?`)\n- Dictionary statistics and analytics\n- Multi-language support\n- Batch dictionary checks, prefix completion and a random word\n- Several pattern searches in one request\n- MCP (Model Context Protocol) JSON-RPC endpoint\n- OpenAI-compatible chat completions\n- This specification as JSON at `/openapi.json`\n\n**Rate Limiting:**\n- 120 requests per 60 seconds for all endpoints except `/api/v1/healthz`\n- Rate limit headers: `X-RateLimit-Limit`, `X-RateLimit-Window`, `Retry-After`\n",
    "version": "1.0.0",
    "contact": {
      "name": "All The Words",
      "url": "https://allthewords.app"
    },
    "license": {
      "name": "All rights reserved (SPDX: UNLICENSED)"
    }
  },
  "servers": [
    {
      "url": "https://api.allthewords.app",
      "description": "Production server"
    }
  ],
  "paths": {
    "/api/v1/healthz": {
      "get": {
        "tags": [
          "Health"
        ],
        "summary": "Health check",
        "description": "Health check endpoint for uptime and deployment probes. Returns service status.",
        "operationId": "healthz",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Service is unavailable"
          }
        },
        "security": []
      }
    },
    "/api/v1/languages": {
      "get": {
        "tags": [
          "Languages"
        ],
        "summary": "List supported languages",
        "description": "Returns all supported languages with their dictionary sizes and word counts.",
        "operationId": "listLanguages",
        "responses": {
          "200": {
            "description": "List of supported languages",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "languages": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "code": {
                            "type": "string",
                            "description": "ISO 639-1 language code",
                            "example": "en"
                          },
                          "name": {
                            "type": "string",
                            "description": "Language name",
                            "example": "English"
                          },
                          "localized_name": {
                            "type": "string",
                            "description": "Language name in its native form",
                            "example": "English"
                          },
                          "word_count": {
                            "type": "integer",
                            "description": "Total number of words in dictionary",
                            "example": 450000
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/api/v1/search/pattern": {
      "get": {
        "tags": [
          "Search"
        ],
        "summary": "Pattern search",
        "description": "Find words matching a pattern. Perfect for Wordle, crossword puzzles, and word games.\n\n**Wildcards:**\n- Use `?` for one unknown position\n- Use `*` for one or more unknown letters, so the word length can vary\n- Example: `? ? A ? E` finds 5-letter words with A in position 3 and E at position 5\n- Example: `b*` finds words that start with b and are at least two letters long\n",
        "operationId": "searchPattern",
        "parameters": [
          {
            "name": "lang",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Language code (e.g., 'en', 'es', 'fr')",
            "example": "en"
          },
          {
            "name": "pattern",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Pattern with wildcards (? for one unknown position, * for one or more unknown letters)",
            "example": "?a?e"
          },
          {
            "name": "contains",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "r"
          },
          {
            "name": "excludes",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "t"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 200
            },
            "description": "Number of results to return (max 200)",
            "example": 20
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Number of results to skip (for pagination)",
            "example": 0
          }
        ],
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/api/v1/search/anagram": {
      "get": {
        "tags": [
          "Search"
        ],
        "summary": "Anagram solver",
        "description": "Find all words that can be formed from a set of letters. Perfect for Scrabble, Wordfeud, and anagram puzzles.\n\n**Blank Tiles:**\n- Use `?` or `_` for blank tiles (wildcards)\n- Example: `react?` finds words formable from letters r,e,a,c,t plus one blank tile\n",
        "operationId": "searchAnagram",
        "parameters": [
          {
            "name": "lang",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Language code (e.g., 'en', 'es', 'fr')",
            "example": "en"
          },
          {
            "name": "letters",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Letters to form words from (1-50 characters). Use ? for blanks.",
            "example": "react"
          },
          {
            "name": "pattern",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Full-word pattern filter. `?` matches exactly one arbitrary\nletter, `*` matches one or more arbitrary letters. The pattern must\nmatch the whole word (case-insensitive); omit it for no pattern\nconstraint. Max 50 characters.\n",
            "example": "v*e"
          },
          {
            "name": "min_length",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Minimum word length",
            "example": 3
          },
          {
            "name": "max_length",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Maximum word length",
            "example": 7
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 200
            },
            "description": "Number of results to return (max 200)",
            "example": 20
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Number of results to skip (for pagination)",
            "example": 0
          }
        ],
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/api/v1/search/patterns": {
      "get": {
        "tags": [
          "Search"
        ],
        "summary": "Batch pattern search",
        "description": "Answer several pattern searches in one request. Each `pattern` query\nparameter is one search, and the answer carries one ordinary search\nresponse per pattern, in the order asked, so a client decodes the batch\nwith the code it already uses for `/api/v1/search/pattern`.\n\n`contains`, `excludes`, `limit` and `offset` apply to every pattern in the\nrequest. Every pattern is validated before any query runs, so a request is\nanswered whole or refused whole: one invalid pattern refuses the batch with\nthe error code of the single-pattern route and the `index` of the offending\npattern in the error `details`.\n\nThe route is a GET with no request body, so the API stays read-only. At most\nten patterns per request; a longer list answers `too_many_patterns`.\n",
        "operationId": "searchPatternBatch",
        "parameters": [
          {
            "name": "lang",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Language code (e.g., 'en', 'es', 'fr')",
            "example": "en"
          },
          {
            "name": "pattern",
            "in": "query",
            "required": true,
            "style": "form",
            "explode": true,
            "schema": {
              "type": "array",
              "maxItems": 10,
              "items": {
                "type": "string"
              }
            },
            "description": "One pattern per query parameter, repeated up to ten times. `?` matches\nexactly one unknown position, `*` one or more unknown letters.\n",
            "example": [
              "?a?e",
              "ca*"
            ]
          },
          {
            "name": "contains",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Applied to every pattern in the request",
            "example": "r"
          },
          {
            "name": "excludes",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Applied to every pattern in the request",
            "example": "t"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 200
            },
            "description": "Number of results per pattern (max 200)",
            "example": 20
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Number of results to skip per pattern",
            "example": 0
          }
        ],
        "responses": {
          "200": {
            "description": "One search response per pattern, in the order asked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchSearchResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/api/v1/stats/languages/{lang}": {
      "get": {
        "tags": [
          "Statistics"
        ],
        "summary": "Language statistics",
        "description": "Returns **search-activity** statistics for one language: how many search\nevents have been recorded for it.\n\nThis endpoint reports search counts only. It does not return the\nper-language dictionary aggregates (word count, average length, average\npoints, maximum word length) or behaviour breakdowns that an earlier\nrevision of this document described.\n",
        "operationId": "getLanguageStats",
        "parameters": [
          {
            "name": "lang",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Language code (e.g., 'en', 'es', 'fr')",
            "example": "en"
          }
        ],
        "responses": {
          "200": {
            "description": "Search counts for the language",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "api_version": {
                      "type": "string",
                      "example": "v1"
                    },
                    "generated_at_utc": {
                      "type": "string",
                      "description": "When the payload was generated (RFC 3339, UTC)",
                      "example": "2026-09-11T18:41:56Z"
                    },
                    "language": {
                      "type": "string",
                      "description": "Language code the count belongs to",
                      "example": "en"
                    },
                    "search_count": {
                      "type": "integer",
                      "description": "Number of recorded search events for this language",
                      "example": 11743
                    }
                  },
                  "required": [
                    "api_version",
                    "generated_at_utc",
                    "language",
                    "search_count"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/api/v1/stats/global": {
      "get": {
        "tags": [
          "Statistics"
        ],
        "summary": "Global statistics",
        "description": "Returns the recorded search-event counts for **every** language that has\nat least one recorded search, ordered by count (descending).\n\nEach language's recorded searches count as one bucket; a language with\nno recorded searches is absent from the list rather than reported as\nzero.\n",
        "operationId": "getGlobalStats",
        "responses": {
          "200": {
            "description": "Search counts per language",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "api_version": {
                      "type": "string",
                      "example": "v1"
                    },
                    "generated_at_utc": {
                      "type": "string",
                      "description": "When the payload was generated (RFC 3339, UTC)",
                      "example": "2026-09-11T18:41:56Z"
                    },
                    "search_counts_by_language": {
                      "type": "array",
                      "description": "One entry per language with recorded searches, count descending",
                      "items": {
                        "type": "object",
                        "properties": {
                          "language": {
                            "type": "string",
                            "example": "en"
                          },
                          "search_count": {
                            "type": "integer",
                            "example": 11743
                          }
                        },
                        "required": [
                          "language",
                          "search_count"
                        ]
                      }
                    }
                  },
                  "required": [
                    "api_version",
                    "generated_at_utc",
                    "search_counts_by_language"
                  ]
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/api/v1/word/{lang}/{word}": {
      "get": {
        "tags": [
          "Words"
        ],
        "summary": "Word details",
        "description": "Get detailed information about a specific word including definition, related words, and cross-language availability.",
        "operationId": "getWordDetails",
        "parameters": [
          {
            "name": "lang",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Language code (e.g., 'en', 'es', 'fr')",
            "example": "en"
          },
          {
            "name": "word",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The word to look up",
            "example": "hello"
          }
        ],
        "responses": {
          "200": {
            "description": "Word details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WordDetailResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "description": "Word not found in dictionary"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/api/v1/words/{lang}": {
      "get": {
        "tags": [
          "Words"
        ],
        "summary": "Browse words",
        "description": "Browse dictionary words with optional length, prefix, suffix, and contains filters.\nReturns complete (uncapped) match lists with pagination — mirrors the web word-list\npages (/words/{length}/{letter}, /words/starting-with/..., /words/containing/...).\nAt least one of `length`, `prefix`, `suffix`, or `contains` is required.\nResults are sorted by length then alphabetically.\n",
        "operationId": "browseWords",
        "parameters": [
          {
            "name": "lang",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Language code (e.g., 'en', 'es', 'fr')",
            "example": "en"
          },
          {
            "name": "length",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 2,
              "maximum": 50
            },
            "description": "Exact word length",
            "example": 5
          },
          {
            "name": "prefix",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 5
            },
            "description": "Words starting with these letters",
            "example": "a"
          },
          {
            "name": "suffix",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 6
            },
            "description": "Words ending with these letters",
            "example": "ing"
          },
          {
            "name": "contains",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 5
            },
            "description": "Words containing these letters",
            "example": "qu"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 200
            },
            "description": "Number of results to return (max 200)",
            "example": 20
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Number of results to skip (for pagination)",
            "example": 0
          }
        ],
        "responses": {
          "200": {
            "description": "Browse results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WordsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/api/v1/words/{lang}/lengths": {
      "get": {
        "tags": [
          "Words"
        ],
        "summary": "Word counts by length",
        "description": "Returns per-length word counts for one language (the data behind the /{lang}/words hub page).",
        "operationId": "getWordLengths",
        "parameters": [
          {
            "name": "lang",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Language code (e.g., 'en', 'es', 'fr')",
            "example": "en"
          }
        ],
        "responses": {
          "200": {
            "description": "Per-length counts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WordLengthsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/api/v1/words/{lang}/exists": {
      "get": {
        "tags": [
          "Words"
        ],
        "summary": "Check many words at once",
        "description": "Answer one dictionary question per word in a single request, so a client\nvalidating a rack, a board or a word list does not spend one rate-limit\nslot per word. Words are compared after the same lower-case, trimmed\nnormalisation the single-word route applies, and are answered in the order\nasked. A word the dictionary does not hold still gets an entry, with\n`present: false` and no `length` or `points`. At most 100 words per request;\na longer list answers `too_many_words`.\n",
        "operationId": "checkWords",
        "parameters": [
          {
            "name": "lang",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Language code (e.g., 'en', 'es', 'fr')",
            "example": "en"
          },
          {
            "name": "words",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated words to check, at most 100",
            "example": "huis,kaas,zzz"
          }
        ],
        "responses": {
          "200": {
            "description": "One entry per requested word, in the order asked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WordExistsResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/api/v1/suggest": {
      "get": {
        "tags": [
          "Words"
        ],
        "summary": "Complete a prefix",
        "description": "Words that start with `prefix`, ordered by length and then alphabetically,\nfor a search box that suggests as the reader types. The match is the same\nanchored prefix match the word-list browse uses, so a one-letter prefix is\nallowed and the hard limit answers it.\n\nAt most 20 words come back: `limit` defaults to 20 and is capped at 20, and\n`has_more` says whether the dictionary holds more. A prefix that matches\nnothing is an empty list with `200`, never an error.\n",
        "operationId": "suggestWords",
        "parameters": [
          {
            "name": "lang",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Language code (e.g., 'en', 'es', 'fr')",
            "example": "en"
          },
          {
            "name": "prefix",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 50
            },
            "description": "Letters every suggestion must start with (letters only)",
            "example": "ka"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 20
            },
            "description": "Number of suggestions to return (max 20)",
            "example": 10
          }
        ],
        "responses": {
          "200": {
            "description": "The capped, ordered suggestion list",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuggestResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/api/v1/random": {
      "get": {
        "tags": [
          "Words"
        ],
        "summary": "Random word",
        "description": "One word, chosen uniformly from the words that match the filters, so a\npuzzle, a lesson or a demo can ask for \"some five-letter word\" in one\nrequest instead of walking pages. The handler counts the filtered rows and\nthen reads one row at a random offset, so no query sorts a whole language\ntable.\n\n`length` and `min_points` are optional and both narrow the choice. A filter\nthat matches nothing answers `404` with the `no_match` error code, never an\nempty `200`. `has_points` is false for a language with no tile values, where\n`points` is always 0.\n",
        "operationId": "randomWord",
        "parameters": [
          {
            "name": "lang",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Language code (e.g., 'en', 'es', 'fr')",
            "example": "en"
          },
          {
            "name": "length",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 2,
              "maximum": 50
            },
            "description": "Exact word length",
            "example": 5
          },
          {
            "name": "min_points",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0
            },
            "description": "Smallest point value the word may have",
            "example": 10
          }
        ],
        "responses": {
          "200": {
            "description": "One word with its length and points",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RandomWordResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "description": "No word matches the filters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": {
                    "code": "no_match",
                    "message": "no word matches those filters"
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "tags": [
          "MCP"
        ],
        "summary": "MCP JSON-RPC endpoint",
        "description": "Model Context Protocol (MCP) JSON-RPC 2.0 endpoint for tool-based interactions.\n\n**Methods:**\n- `initialize` - Initialize connection\n- `ping` - Liveness check (returns an empty result)\n- `tools/list` - List available tools\n- `tools/call` - Execute a tool\n\nJSON-RPC notifications (messages without an `id`, such as\n`notifications/initialized`, which clients send right after\n`initialize`) are accepted and answered with `202 Accepted` and no\nbody, as JSON-RPC 2.0 requires.\n\n**Available Tools:**\n- `list_languages` - List supported languages\n- `search_pattern` - Pattern search\n- `search_anagram` - Anagram solver\n- `get_language_stats` - Language statistics\n- `get_global_stats` - Global statistics\n- `get_word_details` - Word definition, families, and cross-language info\n- `list_words` - Browse dictionary words (length/prefix/suffix/contains filters)\n- `get_word_lengths` - Per-length word counts\n",
        "operationId": "mcpEndpoint",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "jsonrpc",
                  "method"
                ],
                "properties": {
                  "jsonrpc": {
                    "type": "string",
                    "enum": [
                      "2.0"
                    ]
                  },
                  "id": {
                    "type": [
                      "string",
                      "integer",
                      null
                    ]
                  },
                  "method": {
                    "type": "string",
                    "enum": [
                      "initialize",
                      "ping",
                      "tools/list",
                      "tools/call"
                    ]
                  },
                  "params": {
                    "type": "object"
                  }
                }
              },
              "examples": {
                "initialize": {
                  "summary": "Initialize connection",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 1,
                    "method": "initialize"
                  }
                },
                "listTools": {
                  "summary": "List available tools",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 2,
                    "method": "tools/list"
                  }
                },
                "callTool": {
                  "summary": "Call search_pattern tool",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 3,
                    "method": "tools/call",
                    "params": {
                      "name": "search_pattern",
                      "arguments": {
                        "lang": "en",
                        "pattern": "?a?e"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "jsonrpc": {
                      "type": "string"
                    },
                    "id": {
                      "type": [
                        "string",
                        "integer",
                        null
                      ]
                    },
                    "result": {
                      "type": "object"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "integer"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed (MCP requires POST)"
          },
          "413": {
            "description": "Request body exceeds 64KB limit"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "tags": [
          "OpenAI Compatible"
        ],
        "summary": "List models",
        "description": "Returns available models for OpenAI-compatible clients. Lists the MCP-enabled model.",
        "operationId": "listModels",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of available models",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "example": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "example": "allthewords-mcp-1"
                          },
                          "object": {
                            "type": "string",
                            "example": "model"
                          },
                          "created": {
                            "type": "integer",
                            "example": 1700000000
                          },
                          "owned_by": {
                            "type": "string",
                            "example": "allthewords"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "tags": [
          "OpenAI Compatible"
        ],
        "summary": "Chat completions",
        "description": "OpenAI-compatible chat completions endpoint supporting tool-calling style interactions.\nMaps to the same functionality exposed via MCP tools.\n\n**Features:**\n- Text-based chat completions\n- Tool-calling with function definitions\n- Same tool set as MCP endpoint\n\n**Note:** Streaming is not supported.\n",
        "operationId": "chatCompletions",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "messages"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "example": "allthewords-mcp-1"
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "role"
                      ],
                      "properties": {
                        "role": {
                          "type": "string",
                          "enum": [
                            "system",
                            "user",
                            "assistant",
                            "tool"
                          ]
                        },
                        "content": {
                          "type": [
                            "string",
                            "object",
                            null
                          ]
                        },
                        "name": {
                          "type": "string"
                        },
                        "tool_call_id": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "tools": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "function": {
                          "type": "object"
                        }
                      }
                    }
                  },
                  "tool_choice": {
                    "type": [
                      "string",
                      "object"
                    ]
                  },
                  "stream": {
                    "type": "boolean",
                    "description": "Not supported - will error if true"
                  }
                }
              },
              "examples": {
                "simple": {
                  "summary": "Simple completion",
                  "value": {
                    "model": "allthewords-mcp-1",
                    "messages": [
                      {
                        "role": "user",
                        "content": "Find anagrams for react"
                      }
                    ]
                  }
                },
                "withTools": {
                  "summary": "With tool calling",
                  "value": {
                    "model": "allthewords-mcp-1",
                    "messages": [
                      {
                        "role": "user",
                        "content": "Search for pattern"
                      }
                    ],
                    "tools": [
                      {
                        "type": "function",
                        "function": {
                          "name": "search_pattern",
                          "description": "Find words matching a pattern"
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat completion response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "object": {
                      "type": "string"
                    },
                    "created": {
                      "type": "integer"
                    },
                    "model": {
                      "type": "string"
                    },
                    "choices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "index": {
                            "type": "integer"
                          },
                          "message": {
                            "type": "object",
                            "properties": {
                              "role": {
                                "type": "string"
                              },
                              "content": {
                                "type": "string"
                              },
                              "tool_calls": {
                                "type": "array"
                              }
                            }
                          },
                          "finish_reason": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "tags": [
          "Documentation"
        ],
        "summary": "This specification as JSON",
        "description": "The same OpenAPI 3.0 document as `/static/openapi.yaml`, rendered as JSON,\nwhich is what client generators and gateways read. The YAML file is the\nsource: `static/openapi.json` is generated from it by\n`scripts/openapi_json.py`, and the contract test fails when the two files\ndescribe different paths.\n",
        "operationId": "getOpenAPISpec",
        "responses": {
          "200": {
            "description": "The complete OpenAPI document",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "openapi": {
                      "type": "string",
                      "example": "3.0.3"
                    },
                    "info": {
                      "type": "object"
                    },
                    "paths": {
                      "type": "object"
                    }
                  },
                  "required": [
                    "openapi",
                    "info",
                    "paths"
                  ]
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimitExceeded"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Word": {
        "type": "object",
        "properties": {
          "word": {
            "type": "string",
            "description": "The word itself",
            "example": "care"
          },
          "length": {
            "type": "integer",
            "description": "Number of letters in the word",
            "example": 4
          },
          "points": {
            "type": "integer",
            "description": "Scrabble/Wordfeud point value",
            "example": 6
          }
        },
        "required": [
          "word",
          "length",
          "points"
        ]
      },
      "SearchResponse": {
        "type": "object",
        "properties": {
          "tool": {
            "type": "string",
            "description": "Tool used for the search",
            "enum": [
              "pattern",
              "anagram"
            ],
            "example": "pattern"
          },
          "language": {
            "type": "string",
            "description": "Language code",
            "example": "en"
          },
          "query": {
            "type": "string",
            "description": "The search query",
            "example": "?a?e"
          },
          "contains": {
            "type": "string",
            "description": "Letters required in the word (if specified)",
            "example": "r"
          },
          "excludes": {
            "type": "string",
            "description": "Letters excluded from the word (if specified)",
            "example": "t"
          },
          "min_length": {
            "type": "string",
            "description": "Minimum length filter (if specified)",
            "example": "3"
          },
          "max_length": {
            "type": "string",
            "description": "Maximum length filter (if specified)",
            "example": "7"
          },
          "pattern": {
            "type": "string",
            "description": "Full-word pattern filter applied to the results (if specified).",
            "example": "v*e"
          },
          "truncated": {
            "type": "boolean",
            "description": "Whether the match set was cut short — either more matches existed\nthan `maxAnagramResults` (5,000) or the candidate scan hit its\nbounded-work limit. When true, the returned words are the best\navailable results, not an exhaustive list.\n",
            "example": false
          },
          "total": {
            "type": "integer",
            "description": "Total number of matching words",
            "example": 42
          },
          "offset": {
            "type": "integer",
            "description": "Current offset in pagination",
            "example": 0
          },
          "limit": {
            "type": "integer",
            "description": "Current limit in pagination",
            "example": 20
          },
          "returned": {
            "type": "integer",
            "description": "Number of words returned in this response",
            "example": 20
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether more results are available",
            "example": true
          },
          "description": {
            "type": "string",
            "description": "Human-readable description of the search",
            "example": "Searching for words matching pattern '?a?e' in English"
          },
          "words": {
            "type": "array",
            "description": "List of matching words",
            "items": {
              "$ref": "#/components/schemas/Word"
            }
          }
        },
        "required": [
          "tool",
          "language",
          "query",
          "total",
          "offset",
          "limit",
          "returned",
          "has_more",
          "description",
          "words"
        ]
      },
      "WordsResponse": {
        "type": "object",
        "properties": {
          "tool": {
            "type": "string",
            "description": "Always \"words\" for this endpoint",
            "example": "words"
          },
          "language": {
            "type": "string",
            "description": "Language code",
            "example": "en"
          },
          "length": {
            "type": "integer",
            "description": "Exact length filter applied (omitted when unset)",
            "example": 5
          },
          "prefix": {
            "type": "string",
            "description": "Prefix filter applied (omitted when unset)",
            "example": "a"
          },
          "suffix": {
            "type": "string",
            "description": "Suffix filter applied (omitted when unset)",
            "example": "ing"
          },
          "contains": {
            "type": "string",
            "description": "Contains filter applied (omitted when unset)",
            "example": "qu"
          },
          "total": {
            "type": "integer",
            "description": "Total number of matching words (uncapped for browse)",
            "example": 715
          },
          "offset": {
            "type": "integer",
            "description": "Current offset in pagination",
            "example": 0
          },
          "limit": {
            "type": "integer",
            "description": "Current limit in pagination",
            "example": 20
          },
          "returned": {
            "type": "integer",
            "description": "Number of words returned in this response",
            "example": 20
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether more results are available",
            "example": true
          },
          "truncated": {
            "type": "boolean",
            "description": "Always false for browse (lists are uncapped)",
            "example": false
          },
          "description": {
            "type": "string",
            "description": "Human-readable summary of the query",
            "example": "5-letter words starting with 'a' in English (715 matches)"
          },
          "words": {
            "type": "array",
            "description": "List of matching words, sorted by length then alphabetically",
            "items": {
              "$ref": "#/components/schemas/Word"
            }
          }
        },
        "required": [
          "tool",
          "language",
          "total",
          "offset",
          "limit",
          "returned",
          "has_more",
          "truncated",
          "description",
          "words"
        ]
      },
      "WordLengthsResponse": {
        "type": "object",
        "properties": {
          "language": {
            "type": "string",
            "description": "Language code",
            "example": "en"
          },
          "language_name": {
            "type": "string",
            "description": "Language name",
            "example": "English"
          },
          "total_words": {
            "type": "integer",
            "description": "Total number of words in the dictionary",
            "example": 517000
          },
          "lengths": {
            "type": "array",
            "description": "Per-length word counts, ascending by length",
            "items": {
              "type": "object",
              "properties": {
                "length": {
                  "type": "integer",
                  "description": "Word length",
                  "example": 5
                },
                "count": {
                  "type": "integer",
                  "description": "Number of words of this length",
                  "example": 15803
                }
              }
            }
          }
        }
      },
      "WordDetailResponse": {
        "type": "object",
        "properties": {
          "word": {
            "type": "string",
            "example": "hello"
          },
          "language": {
            "type": "string",
            "example": "en"
          },
          "language_name": {
            "type": "string",
            "example": "English"
          },
          "length": {
            "type": "integer",
            "example": 5
          },
          "points": {
            "type": "integer",
            "example": 8
          },
          "has_points": {
            "type": "boolean",
            "example": true
          },
          "definition": {
            "type": "object",
            "nullable": true,
            "description": "Wiktionary definition if available"
          },
          "word_families": {
            "type": "object",
            "description": "Related words (starts_with, ends_with, contains)"
          },
          "cross_languages": {
            "type": "array",
            "description": "Same word in other language dictionaries",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "BatchSearchResponse": {
        "type": "object",
        "properties": {
          "language": {
            "type": "string",
            "description": "Language code every pattern was searched in",
            "example": "en"
          },
          "contains": {
            "type": "string",
            "description": "Contains filter applied to every pattern (omitted when unset)",
            "example": "r"
          },
          "excludes": {
            "type": "string",
            "description": "Excludes filter applied to every pattern (omitted when unset)",
            "example": "t"
          },
          "limit": {
            "type": "integer",
            "description": "Limit applied to every pattern",
            "example": 20
          },
          "offset": {
            "type": "integer",
            "description": "Offset applied to every pattern",
            "example": 0
          },
          "count": {
            "type": "integer",
            "description": "Number of patterns answered",
            "example": 2
          },
          "results": {
            "type": "array",
            "description": "One search response per pattern, in the order asked",
            "items": {
              "$ref": "#/components/schemas/SearchResponse"
            }
          }
        },
        "required": [
          "language",
          "limit",
          "offset",
          "count",
          "results"
        ]
      },
      "WordExistsResponse": {
        "type": "object",
        "properties": {
          "language": {
            "type": "string",
            "description": "Language the words were checked in",
            "example": "en"
          },
          "requested": {
            "type": "integer",
            "description": "Number of words in the request",
            "example": 3
          },
          "found": {
            "type": "integer",
            "description": "Number of requested words the dictionary holds",
            "example": 2
          },
          "words": {
            "type": "array",
            "description": "One entry per requested word, in the order asked",
            "items": {
              "type": "object",
              "properties": {
                "word": {
                  "type": "string",
                  "description": "The word in the lower-case, trimmed form that was checked",
                  "example": "huis"
                },
                "present": {
                  "type": "boolean",
                  "description": "Whether this language's dictionary holds the word",
                  "example": true
                },
                "length": {
                  "type": "integer",
                  "description": "Word length (absent when the word is not present)",
                  "example": 4
                },
                "points": {
                  "type": "integer",
                  "description": "Point value (absent when the word is not present)",
                  "example": 7
                }
              },
              "required": [
                "word",
                "present"
              ]
            }
          }
        },
        "required": [
          "language",
          "requested",
          "found",
          "words"
        ]
      },
      "SuggestResponse": {
        "type": "object",
        "properties": {
          "language": {
            "type": "string",
            "description": "Language code",
            "example": "en"
          },
          "prefix": {
            "type": "string",
            "description": "Normalised prefix every suggestion starts with",
            "example": "ka"
          },
          "limit": {
            "type": "integer",
            "description": "The cap that was applied",
            "example": 20
          },
          "returned": {
            "type": "integer",
            "description": "Number of suggestions in this response",
            "example": 12
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether the dictionary holds more words with this prefix",
            "example": false
          },
          "words": {
            "type": "array",
            "description": "Suggestions, sorted by length then alphabetically",
            "items": {
              "$ref": "#/components/schemas/Word"
            }
          }
        },
        "required": [
          "language",
          "prefix",
          "limit",
          "returned",
          "has_more",
          "words"
        ]
      },
      "RandomWordResponse": {
        "type": "object",
        "properties": {
          "word": {
            "type": "string",
            "example": "pizza"
          },
          "language": {
            "type": "string",
            "example": "en"
          },
          "length": {
            "type": "integer",
            "example": 5
          },
          "points": {
            "type": "integer",
            "example": 25
          },
          "has_points": {
            "type": "boolean",
            "description": "False for a language with no tile values, where points is always 0",
            "example": true
          }
        },
        "required": [
          "word",
          "language",
          "length",
          "points",
          "has_points"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "Error code for programmatic handling",
                "example": "missing_pattern"
              },
              "message": {
                "type": "string",
                "description": "Human-readable error message",
                "example": "Missing required parameter: pattern"
              },
              "details": {
                "type": "object",
                "description": "Additional error details (optional)"
              }
            }
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Bad request - missing or invalid parameters",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "missingParam": {
                "summary": "Missing required parameter",
                "value": {
                  "error": {
                    "code": "missing_pattern",
                    "message": "Missing required parameter: pattern"
                  }
                }
              },
              "invalidLength": {
                "summary": "Invalid length range",
                "value": {
                  "error": {
                    "code": "invalid_length_range",
                    "message": "min_length cannot exceed max_length"
                  }
                }
              },
              "invalidLanguage": {
                "summary": "Unsupported language code",
                "value": {
                  "error": {
                    "code": "invalid_language",
                    "message": "unsupported language code",
                    "details": {
                      "lang": "zz"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "RateLimitExceeded": {
        "description": "Rate limit exceeded",
        "headers": {
          "X-RateLimit-Limit": {
            "schema": {
              "type": "integer"
            },
            "description": "Maximum requests allowed in the window"
          },
          "X-RateLimit-Window": {
            "schema": {
              "type": "integer"
            },
            "description": "Time window in seconds"
          },
          "Retry-After": {
            "schema": {
              "type": "integer"
            },
            "description": "Seconds to wait before retrying"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "rate_limited",
                "message": "Too many requests. Please slow down."
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer token required by the MCP and OpenAI-compatible routes. Send it\nas `Authorization: Bearer <token>`. The dictionary routes do not need\none.\n"
      }
    }
  },
  "security": []
}
