Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

llms-txt.ts

172 lines9.3 KB

1/**
2 * The /llms.txt agent guide (PLAN.md task 4.1). Shared module so the /docs
3 * page (7.3) and the distributable skill (7.6) render from the same source.
4 */
5export const llmsTxt = `# modelschemas
6​
7Live AI model schema service. Per-endpoint request/response JSON Schemas and
8model metadata for 30+ monitored providers (OpenAI, Anthropic, Gemini, xAI
9Grok, Mistral, Groq, DeepSeek, and more — GET /v1/providers for the full
10roster), refreshed automatically: model lists every 15 minutes, full OpenAPI
11spec syncs daily. Responses are JSON unless noted (\`text/typescript\`,
12\`application/openapi+json\`).
13​
14## Why use this
15​
16- Discover which models exist *right now*, across providers, by activity
17 (chat, image, video, audio, embeddings, moderation, world, decision, search). Grain=provider
18 catalogs (Grok, OpenAI, …) set \`activity\` on each row and
19 \`schemaEndpointId\` pointing at the shared generation route
20 (\`v1/images/generations\`, \`images/generations\`, …). \`pricing\` is a
21 RateCard (or null when no price is stored). List rows carry a summary:
22 \`{currency, per: 'token', inputPerMillion, outputPerMillion, tiered?}\`
23 at the base rate, or \`{currency, per: 'second' | 'character' | 'image' | …}\`
24 for a card billed by unit. \`currency\` is ISO 4217 (mostly USD; nothing
25 is converted, so compare only like with like); \`?pricing=1\` returns
26 the full card. \`/v1/status\` counts live \`priced\` models per provider
27 and scores \`completeness\` (the share of facts filled: chat, image,
28 video and audio rows on their own fact sets, a null activity as a gap,
29 and origin links; \`score\` is null when nothing is scored). A provider there carries \`docsFailing\`,
30 \`priceClearsRefused\`, \`updateStorm\`, or \`staleProbes\` while its
31 stored docs facts or prices may be stale, one poll rewrote most of its
32 live rows, or a probe record is older than 90 days. A model row's
33 \`requiredRequestHeaders\` lists client-supplied connect headers.
34 \`trainsOnRequestData: true\` means that id's own source says it trains
35 on request data.
36- Fetch a self-contained JSON Schema (refs bundled under $defs) for any
37 provider generation endpoint — request (input) and response (output).
38 A listed model rawId also works as \`{endpointId}\`: it aliases onto that
39 route and pins the request \`model\` field to the one id.
40- Validate a payload server-side before spending tokens on a provider call.
41- Estimate the cost of a call from the stored rate card, in the card's
42 currency (\`POST /v1/estimate\`).
43- Poll /v1/changes (or subscribe via webhooks) to hear about new models and
44 API revisions. A catalog.shape_changed change means the model row itself
45 changed shape (payload.version, payload.notes): re-read openapi.json.
46 /v1 changes are otherwise additive; ignore keys you do not know.
47​
48## Quickstart (no auth needed for reads)
49​
501. GET /v1 — endpoint index.
512. GET /v1/models?activity=chat — cross-provider catalog of chat models.
52 GET /v1/providers/{provider} — one provider's status, counts, and live
53 models per activity.
543. GET /v1/schemas — system-wide index: every provider's activities and
55 endpoint ids in one response (all schemas on the system).
564. GET /v1/schemas/anthropic — activities + endpoint ids for one provider.
575. GET /v1/schemas/anthropic/chat/{endpointId}?kind=input — the JSON Schema
58 for a request body (endpoint ids contain slashes; URL-encode them).
59 Grain=provider models also accept the raw id:
60 \`/v1/schemas/grok/image/grok-imagine-image-2.0?kind=input\`.
616. GET /v1/openapi/{provider} — generation-only OpenAPI (servers, auth,
62 paths). FAL is one queue document: the model id is the endpoint_id path
63 parameter (x-modelschemas-encode: raw — do not percent-encode slashes).
64 Bare, the bodies are untyped; ?activity= inlines each model's own body
65 schema (up to 1024 models); ?model= is that one model's paths. Reactor
66 publishes POST /tokens only. Model commands are input_/output_
67 components tagged x-modelschemas-transport: realtime, not HTTP paths.
68 A filter that matches none: 400
69 spec_requires_selector. HTTP only (no MCP tool).
707. POST /v1/validate {"provider","endpointId","payload"} — check a payload.
718. POST /v1/estimate {"provider","model","request"?,"usage"?} — {amount,
72 currency} for a call from the stored rate card. Missing levers → 422;
73 no card → 404 unknown_pricing. See "Estimate usage" below.
749. GET /v1/changes?since=<unix epoch> — what changed.
75​
76## TypeScript types
77​
78Add \`?format=types\` to a schema read
79(GET /v1/schemas/{provider}/{activity}/{endpointId}) to get a self-contained
80TypeScript module instead of JSON: the schema as a pure const plus generated
81interfaces (\`text/typescript\`, zero imports, tree-shakeable, same ETag
82discipline). \`?optional=undefined\` widens optional properties to
83\`T | undefined\` for exactOptionalPropertyTypes consumers; default is
84\`foo?: T\`. A request \`model\` field is the live catalog union plus
85\`ListedModelId<'provider'>\` (still branded when the catalog is empty).
86Minted by \`listModels\` / \`listProviderModels\` / \`getModel\` (or
87\`asListedModelId\`). Arbitrary \`string\` values do not assign.
88​
89## Hypermedia (HAL, extended)
90​
91Every JSON read response carries \`_links\`: HAL link objects extended with
92\`method\`, \`contentType\`, and an inline \`example\` (a resolvable URL for
93GETs, a request body for POSTs) so you can follow the API without consulting
94docs. Templated hrefs (RFC 6570) set \`"templated": true\` and always include
95an example. Start at GET /v1 and follow \`_links\`.
96​
97## Long-polling
98​
99No sleep tool? Add \`?wait=30\` (seconds, cap 60, \`30s\` form accepted) to
100GET /v1/changes or GET /v1/status: the request holds until new data lands or
101the window expires, then returns whatever is current. One request, one
102rate-limit token.
103​
104## Caching
105​
106Catalog and current schema reads (\`/v1/models\`, \`/v1/providers\`, \`/v1/schemas\`,
107\`/v1/openapi/{provider}\`) send \`Cache-Control: public, max-age=900\` (the
10815-minute model poll) and are edge-cached. A schema read with
109\`?version=<content hash>\` is immutable and cached for a year. Responses also
110carry ETag (content hash), Last-Modified, X-Fetched-At and X-Stale-At (unix
111epoch seconds). Send If-None-Match to get 304s. \`/v1/changes\` and
112\`/v1/status\` are not edge-cached. A response served from the edge does not
113run the worker, so it does not count toward the rate limit, with or without
114Authorization. Only cache misses are counted.
115​
116## Auth (optional — unlocks higher rate limits + webhooks)
117​
118- Agent-auth protocol: discovery at /.well-known/agent-configuration,
119 register at POST /api/auth/agent/register, then execute capabilities with
120 short-lived JWTs.
121- Simple alternative: POST /v1/agents/register-key { "name" } returns an API
122 key once; send it as Authorization: Bearer <key>.
123​
124## Machine-readable spec
125​
126GET /openapi.json — OpenAPI 3.1 for this service; every operation has an
127operationId. GET /skill — installable agent skill (SKILL.md) teaching this
128full workflow.
129​
130## Estimate usage
131​
132\`usage\` on POST /v1/estimate takes one of two shapes. A payload that
133mixes them gets 422 mixed_usage.
134​
135- The provider's own usage object, as the API returned it: OpenAI
136 Responses or Chat Completions \`usage\`, Anthropic \`usage\`, or Gemini
137 \`usageMetadata\`. The service maps it to card levers.
138- Card levers. Their counts do not overlap: \`input_tokens\` excludes the
139 tokens in \`cache_read_tokens\`, \`cache_write_tokens\` (5-minute writes)
140 and \`cache_write_1h_tokens\`. A card can also read \`reasoning_tokens\`,
141 \`audio_tokens\`, \`image_tokens\` or \`web_searches\`; a count in one of
142 these is not also in \`input_tokens\` or \`output_tokens\`. The model's
143 \`pricing.inputs\` (GET /v1/models/{provider}/{id}) lists the levers its
144 card reads. A zero card lever the card does not read is dropped. A
145 non-zero one is 422 \`unknown_usage_key\`.
146​
147| Native field | Card lever |
148| --- | --- |
149| OpenAI \`input_tokens\` or \`prompt_tokens\` | \`input_tokens\`, less cached tokens and cache writes |
150| OpenAI \`*_details.cached_tokens\` | \`cache_read_tokens\` |
151| OpenAI \`*_details.cache_write_tokens\` | \`cache_write_tokens\` |
152| OpenAI \`prompt_tokens_details.image_tokens\` | \`image_tokens\` when the card reads it; otherwise it stays in \`input_tokens\` |
153| OpenAI \`prompt_tokens_details.text_tokens\` | not subtracted; it is already inside \`prompt_tokens\` |
154| OpenAI \`output_tokens\` or \`completion_tokens\` | \`output_tokens\` |
155| Anthropic \`input_tokens\` | \`input_tokens\` (already excludes cache) |
156| Anthropic \`cache_read_input_tokens\` | \`cache_read_tokens\` |
157| Anthropic \`cache_creation_input_tokens\` | \`cache_write_tokens\`; 1-hour writes go to \`cache_write_1h_tokens\` |
158| Gemini \`promptTokenCount\` | \`input_tokens\`, less \`cachedContentTokenCount\` |
159| Gemini \`cachedContentTokenCount\` | \`cache_read_tokens\` |
160| Gemini \`candidatesTokenCount\` + \`thoughtsTokenCount\` | \`output_tokens\` |
161​
162Reasoning, audio, image and video counts move to their own lever only
163when the card reads that lever. Otherwise they stay in the total, because
164the source bills them at that rate. Example: gpt-5 usage
165\`{"input_tokens":12000,"input_tokens_details":{"cached_tokens":4000},"output_tokens":800}\`
166prices 8000 input, 4000 cached and 800 output tokens.
167​
168## Errors
169​
170All errors are JSON: { "error": { "code", "message" } }. Messages include
171remedies (e.g. valid provider ids on a 404).