> For AI agents: the complete documentation index is available at https://types-mediawiki-response.pages.dev/llms.txt, the full documentation bundle is available at https://types-mediawiki-response.pages.dev/llms-full.txt.

# Getting started

Type declarations for MediaWiki Action API responses, written for `formatversion=2` with a field union spanning 1.39–1.47. The package ships declarations only (`dist/*.d.ts`) — no runtime code, so importing it adds nothing to your bundle.


## Install

```sh [npm]
npm install -D types-mediawiki-response
```

```sh [yarn]
yarn add -D types-mediawiki-response
```

```sh [pnpm]
pnpm add -D types-mediawiki-response
```

```sh [bun]
bun add -d types-mediawiki-response
```

```sh [deno]
deno add npm:types-mediawiki-response
```
## Cast the response of an action
Each `action` maps to one `ApiXxxResponse`. For example, fetching page revisions:
```ts
import type { ApiQueryResponse } from "types-mediawiki-response";

const res = (await api.get({
  action: "query",
  prop: "revisions",
  titles,
  formatversion: "2",
})) as ApiQueryResponse;

console.log(res.query.pages[0]?.revisions);
```
Pass `formatversion: "2"` on the request — the library's types cover fv2 only. Every response type is listed in the [API reference](https://types-mediawiki-response.pages.dev/api/index.md).

## Handling errors

Casting to `ApiXxxResponse` only asserts **no root error** — which is not the same as "the operation succeeded". How to handle a failing response depends mainly on the client:

- Clients that handle root errors for you, such as `mw.Api`, throw as soon as the response carries a root `error` / `errors` — just wrap the request in a `try`/`catch`, and no extra handling of the response type is needed.
- Clients that hand the error response back as-is (native `fetch`, for example) need the type wrapped with [`ApiResponseWith<T>`](https://types-mediawiki-response.pages.dev/api/core/ApiResponseWith.md) and a narrowing on `error` / `errors`.

See [Envelope and error handling](https://types-mediawiki-response.pages.dev/guide/errors.md) for the details.

## Extensions

Core types cover MediaWiki core modules only. Fields contributed by extensions are split into opt-in packs: a single type-only import in any file covered by your tsconfig activates the pack program-wide:

```ts
// Activate the CheckUser extension
import type {} from "types-mediawiki-response/ext/checkuser";
```

A field that shows up in the real response but not in the core types usually means an extension provides it — that is your cue to activate its pack.

An extension action (`action=thank`, `action=shortenurl`, …) instead exports a standalone response type — import it by name where you call it, like any core action response:

```ts
import type { ApiThankResponse } from "types-mediawiki-response/ext/thanks";

const res: ApiThankResponse = await api.post({ action: "thank", rev });
res.result?.recipient; // the thanked user
```

See [Opt-in extension packs](https://types-mediawiki-response.pages.dev/guide/ext-packs.md).

## Working with AI

Besides the copy-Markdown feature at the top of each page, this docs site also publishes llms.txt files alongside its content:

- [llms.txt](https://types-mediawiki-response.pages.dev/llms.txt): an index file with descriptions and links for every page on the site
  ```
  https://types-mediawiki-response.pages.dev/llms.txt
  ```
- [llms-full.txt](https://types-mediawiki-response.pages.dev/llms-full.txt): the entire site content merged into one file
  ```
  https://types-mediawiki-response.pages.dev/llms-full.txt
  ```

Copy whichever link fits your use case and hand it to your agent.

## Next steps

- [Envelope and error handling](https://types-mediawiki-response.pages.dev/guide/errors.md)
- [Query responses](https://types-mediawiki-response.pages.dev/guide/query.md)
- [Field conventions](https://types-mediawiki-response.pages.dev/guide/conventions.md)
- [Opt-in extension packs](https://types-mediawiki-response.pages.dev/guide/ext-packs.md)
- [Examples](https://types-mediawiki-response.pages.dev/guide/examples.md)
