Getting Started
This guide walks you through installing strapi-typed-client, registering the Strapi plugin, generating types, and making your first typed API call.
Requirements
- Strapi v5 (Strapi v4 is not supported)
- Node.js >= 18
Installation
Install the package in both your Strapi backend and your frontend project:
npm install strapi-typed-clientyarn add strapi-typed-clientpnpm add strapi-typed-clientRegister the Strapi Plugin
The package includes a Strapi plugin that exposes your schema via a REST endpoint. Since the strapi field in package.json declares it as a plugin, Strapi auto-discovers it — no manual import or resolve needed.
Enable it in your Strapi project's config/plugins.ts:
// config/plugins.ts
export default {
'strapi-typed-client': {
enabled: true,
config: {
requireAuth: false, // default: false in dev, true in production
},
},
}After adding the config, restart your Strapi server.
WARNING
When requireAuth is not set, the plugin defaults to requiring auth in production (NODE_ENV === 'production') and not requiring it in development. Set it explicitly if you need a specific behavior.
Plugin Endpoints
Once the plugin is active, two endpoints become available:
| Endpoint | Description |
|---|---|
GET /api/strapi-typed-client/schema | Returns the full content-type schema as JSON + hash |
GET /api/strapi-typed-client/schema-hash | Returns only the schema hash (used for change detection) |
TIP
These endpoints are used by the CLI to fetch your schema. You do not need to call them manually.
Creating an API Token
If you enable requireAuth: true (or deploy to production where it's enabled by default), you need an API token. To create one:
- Open the Strapi admin panel.
- Go to Settings → Global Settings → API Tokens.
- Click Create new API Token.
- Set a Name (e.g., "Types Generator"), choose Token type —
Read-onlyis sufficient for schema fetching. - Click Save and copy the token immediately — it is shown only once.
Pass the token to the CLI:
npx strapi-types generate --url http://localhost:1337 --token YOUR_TOKENOr via environment variable:
STRAPI_TOKEN=your-token npx strapi-types generateSee Authentication for more details.
Generate Types
With Strapi running, use the CLI to fetch the schema and generate TypeScript types and a typed client:
npx strapi-types generate --url http://localhost:1337This generates files directly into the installed package (node_modules/strapi-typed-client/dist) so you can import from strapi-typed-client immediately:
| File | Description |
|---|---|
types.d.ts | TypeScript interfaces for all content types and components |
client.js | A typed StrapiClient class with methods for every collection |
index.js | Re-exports everything from types and client |
You can change the output directory with the --output flag:
npx strapi-types generate --url http://localhost:1337 --output ./src/strapiQuick Usage
Once types are generated, create a client and start making typed API calls:
import { StrapiClient } from 'strapi-typed-client'
const strapi = new StrapiClient({
baseURL: 'http://localhost:1337',
})
// Fully typed — autocomplete for filters, sort, populate
const articles = await strapi.articles.find({
filters: { title: { $contains: 'hello' } },
sort: ['createdAt:desc'],
pagination: { page: 1, pageSize: 10 },
})
console.log(articles.data) // Article[]INFO
The client uses the global fetch by default. In Next.js, this means you automatically get all of Next.js's fetch optimizations (caching, deduplication, revalidation). See the Next.js integration guide for details.
Next Steps
- CLI Commands Reference — all CLI options and environment variables
- Client Usage — CRUD operations, auth, error handling
- Populate & Type Inference — nested populate with automatic type narrowing
- Next.js Integration — auto-generation, cache options, ISR