Skip to content

Serve Swagger UI and an OpenAPI description for the local API - #11

Merged
redacid merged 2 commits into
mainfrom
feat/api-openapi
Dec 2, 2026
Merged

redacid merged 2 commits into
mainfrom
feat/api-openapi

Conversation

@redacid

@redacid redacid commented Dec 2, 2026

Copy link
Copy Markdown
Owner

What

The local subscription API (#10) now documents itself:

  • GET /openapi.json: OpenAPI 3.1 description of /v1/models and /v1/chat/completions, covering request and response schemas, SSE streaming, error codes and bearer auth. It imports into Postman, Insomnia or Bruno, or into client generators.
  • GET /docs: a Swagger UI page. Authorize takes the key, and Try it out sends real requests.
  • The API tab gets a Docs row that links both while the API runs.

Security

  • /docs and /openapi.json answer without the key, since they hold no secrets. Every other route still requires it.
  • Without the key, the spec lists only static example models. The live models, which reveal which subscriptions are logged in and run the CLIs to find out, appear only with a valid key. Swagger UI sends the key after Authorize.
  • Every request must have a Host of 127.0.0.1, localhost or [::1] on the API's port; anything else gets 421. This blocks DNS rebinding: a web page pointing its own domain at 127.0.0.1 can no longer read the keyless pages as same-origin.
  • Swagger UI loads swagger-ui-dist@5.17.14 from jsDelivr, pinned and checked with SRI hashes, so the app ships no copy. That page needs internet access; openapi.json does not.

Testing

  • make check: 179 tests. New tests cover:
    • the spec shape and server URL;
    • static vs. live model examples, without and with the key;
    • the Swagger page with SRI;
    • keyless access only to the docs routes;
    • the Host check, including a request with a foreign Host.
  • mkdocs build --strict passes.
  • Checked by hand in a browser against a demo server whose answer function was a stand-in: the page renders, Authorize accepts the key, and Execute on /chat/completions returned the answer and the matching curl command. No real CLI was used from this page.

Docs

  • docs/api.md: new "Swagger UI and OpenAPI" section, the endpoints table, and the Host rule under Security.
  • docs/interface.md: the Docs row.
  • Architecture: the openapi.ts module and the keyless and Host behaviour.
  • API tab screenshot regenerated.

Serhii Rudenko added 2 commits December 2, 2026 10:26
Programs and people using the local API had only a prose page and a curl
example to go by. The API now serves an OpenAPI 3.1 description at
/openapi.json (with the models usable right now as examples for
`model`), so it can be imported into Postman or Insomnia or used to
generate clients, and a Swagger UI page at /docs to browse it and send
requests with the key from the Authorize button.

Both answer without the key because they hold no secrets; every other
route still requires it. Swagger UI loads from jsDelivr at a pinned
version with SRI hashes, so the app ships no copy of it. The API tab
links both while the API runs.
The OpenAPI description is served without the key, but it listed the
models of the logged-in subscriptions, which told any caller which
subscriptions this computer has and ran the CLIs to find out. Without
the key it now has static example models; with the key (Swagger UI
sends it after Authorize) it lists the live ones.

Every request must now be addressed to 127.0.0.1, localhost or [::1]
on the API's port. Otherwise a web page could point its own domain at
127.0.0.1 (DNS rebinding) and read the keyless pages as same-origin.
@redacid
redacid merged commit 3cf1074 into main Dec 2, 2026
8 checks passed
redacid pushed a commit that referenced this pull request Dec 2, 2026
Bump the version and add the changelog entry for Swagger UI and the OpenAPI description of the local API (#11).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant