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

llms-txt.ts

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