2025-11-12 20:29:12 +00:00
# @modrinth/api-client
[](https://www.typescriptlang.org/)
2026-05-06 23:39:06 +01:00
[](LICENSE)
Platform-agnostic TypeScript client for Modrinth's API across Node.js, browsers, Nuxt, and Tauri.
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
**⚠️ We use this internally to power modrinth.com, Modrinth App, and Modrinth Hosting frontends. It may break without any notice, but you are welcome to use it.**
2025-11-12 20:29:12 +00:00
## Installation
```bash
pnpm add @modrinth/api -client
2026-05-06 23:39:06 +01:00
```
Tauri apps also need the optional peer dependency:
```bash
pnpm add @modrinth/api -client @tauri -apps/plugin-http
2025-11-12 20:29:12 +00:00
```
## Usage
2026-05-06 23:39:06 +01:00
### Generic Node.js or Browser Client
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
```ts
import { AuthFeature, GenericModrinthClient, type Labrinth } from '@modrinth/api -client'
2025-11-12 20:29:12 +00:00
const client = new GenericModrinthClient({
userAgent: 'my-app/1.0.0',
features: [new AuthFeature({ token: 'mrp_...' })],
})
2026-05-06 23:39:06 +01:00
const project: Labrinth.Projects.v2.Project = await client.labrinth.projects_v2.get('sodium')
const members = await client.labrinth.projects_v3.getMembers(project.id)
```
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
You can still make direct requests through the same platform layer:
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
```ts
const project = await client.request<Labrinth.Projects.v2.Project>('/project/sodium', {
api: 'labrinth',
version: 2,
})
2025-11-12 20:29:12 +00:00
```
### Nuxt
2026-05-06 23:39:06 +01:00
```ts
import { AuthFeature, CircuitBreakerFeature, NuxtCircuitBreakerStorage, NuxtModrinthClient } from '@modrinth/api -client'
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
export const useModrinthClient = async () => {
2025-11-12 20:29:12 +00:00
const config = useRuntimeConfig()
const auth = await useAuth()
return new NuxtModrinthClient({
2026-05-06 23:39:06 +01:00
userAgent: 'my-nuxt-app/1.0.0',
2025-11-12 20:29:12 +00:00
rateLimitKey: import.meta.server ? config.rateLimitKey : undefined,
features: [
new AuthFeature({
token: async () => auth.value.token,
}),
new CircuitBreakerFeature({
storage: new NuxtCircuitBreakerStorage(),
}),
],
})
}
```
### Tauri
2026-05-06 23:39:06 +01:00
```ts
2025-11-12 20:29:12 +00:00
import { getVersion } from '@tauri -apps/api/app'
2026-05-06 23:39:06 +01:00
import { AuthFeature, TauriModrinthClient } from '@modrinth/api -client'
2025-11-12 20:29:12 +00:00
const version = await getVersion()
const client = new TauriModrinthClient({
userAgent: `modrinth/theseus/${version} (support@modrinth.com)` ,
features: [new AuthFeature({ token: 'mrp_...' })],
})
2026-05-06 23:39:06 +01:00
const project = await client.labrinth.projects_v2.get('sodium')
```
## API Modules
Modules are available as nested properties on the client:
```ts
client.labrinth.projects_v2
client.labrinth.projects_v3
client.labrinth.versions_v3
```
Types are exported from the package root:
```ts
import type { Labrinth } from '@modrinth/api -client'
const project: Labrinth.Projects.v3.Project = await client.labrinth.projects_v3.get('sodium')
2025-11-12 20:29:12 +00:00
```
2026-05-06 23:39:06 +01:00
## Modrinth Hosting API Modules
- These modules are internal to Modrinth and are only supported inside the Modrinth Hosting panel in Modrinth App and on modrinth.com. They should not be expected to work in third-party clients today. We are discussing how to safely expose access to your own server through these APIs in the future.
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
## Base URLs
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
By default, the client uses Modrinth production services:
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
- `labrinthBaseUrl` : `https://api.modrinth.com`
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
Override them for staging or custom deployments:
```ts
2025-11-12 20:29:12 +00:00
const client = new GenericModrinthClient({
userAgent: 'my-app/1.0.0',
2026-05-06 23:39:06 +01:00
labrinthBaseUrl: 'https://staging-api.modrinth.com',
2025-11-12 20:29:12 +00:00
})
```
2026-05-06 23:39:06 +01:00
External APIs can be targeted per request by passing a full URL as `api` and disabling auth:
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
```ts
await client.request('/endpoint', {
api: 'https://example.com',
version: 1,
skipAuth: true,
2025-11-12 20:29:12 +00:00
})
```
## Features
2026-05-06 23:39:06 +01:00
Features wrap requests before they reach the platform implementation:
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
```ts
import { AuthFeature, CircuitBreakerFeature, RetryFeature } from '@modrinth/api -client'
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
const client = new GenericModrinthClient({
features: [new AuthFeature({ token: async () => getToken() }), new RetryFeature({ maxAttempts: 3, backoffStrategy: 'exponential' }), new CircuitBreakerFeature({ maxFailures: 3, resetTimeout: 30_000 })],
2025-11-12 20:29:12 +00:00
})
```
2026-05-06 23:39:06 +01:00
Built-in features include authentication, node auth, retries, circuit breaking, panel version headers, and verbose logging.
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
## Uploads
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
Upload endpoints return an `UploadHandle<T>` with progress and cancellation support:
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
```ts
const upload = client.kyros.files_v0.uploadFile(path, file)
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
upload.onProgress(({ progress }) => {
console.log(Math.round(progress * 100))
2025-11-12 20:29:12 +00:00
})
2026-05-06 23:39:06 +01:00
await upload.promise
2025-11-12 20:29:12 +00:00
```
2026-05-06 23:39:06 +01:00
Uploads use `XMLHttpRequest` for progress tracking and are only available in browser-capable contexts. `NuxtModrinthClient.upload()` throws during SSR.
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
## Third-Party API Typings
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
- This package also includes some third-party API modules and typings used by Modrinth internals. They are not part of the stable public API surface and should be used at your own risk.
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
## Development
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
```bash
pnpm --filter @modrinth/api -client build
pnpm --filter @modrinth/api -client lint
# or pnpm prepr:frontend:lib in turborepo root.
```
2025-11-12 20:29:12 +00:00
2026-05-06 23:39:06 +01:00
When adding a module, add it to `src/modules/index.ts` so it is included in the typed client structure.
2025-11-12 20:29:12 +00:00
## License
2026-05-06 23:39:06 +01:00
Licensed under LGPL-3.0. See [LICENSE ](LICENSE ).