Skip to content

Pagination

AniKura uses offset-based pagination for list queries. The current API uses limit and offset parameters. Cursor-based pagination (GraphQL connections) is planned for a future version.


Limit and Offset

All list queries accept limit and offset:

ParameterTypeDefaultMaxDescription
limitInt2050Number of results to return
offsetInt0Number of results to skip
query {
searchAnime(query: "sword", limit: 20, offset: 0) {
id
titleRomaji
}
}

Iterating Through Results

To paginate through all results, increment offset by limit on each request:

async function* fetchAllAnime(query: string) {
const limit = 50;
let offset = 0;
while (true) {
const response = await fetch("https://api.anikura.io/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": process.env.ANIKURA_API_KEY,
},
body: JSON.stringify({
query: `
query SearchAnime($query: String!, $limit: Int!, $offset: Int!) {
searchAnime(query: $query, limit: $limit, offset: $offset) {
id
titleRomaji
averageScore
}
}
`,
variables: { query, limit, offset },
}),
});
const { data } = await response.json();
const results = data.searchAnime;
if (results.length === 0) break;
yield* results;
offset += limit;
// Stop if fewer results than requested — we've reached the end
if (results.length < limit) break;
}
}

Page Number Pattern

If you prefer page numbers over raw offsets:

function getOffset(page: number, pageSize: number): number {
// Pages are 1-indexed
return (page - 1) * pageSize;
}
// Fetch page 3 with 20 results per page
const page = 3;
const pageSize = 20;
const response = await fetch("https://api.anikura.io/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": process.env.ANIKURA_API_KEY,
},
body: JSON.stringify({
query: `
query {
searchAnime(query: "romance", limit: ${pageSize}, offset: ${getOffset(page, pageSize)}) {
id
titleRomaji
}
}
`,
}),
});

Limits

  • Maximum limit per request: 50
  • Requests exceeding this limit return a validation error
  • Very large offsets may be slower — prefer narrowing queries with filters when possible

Future: Cursor-Based Pagination

Cursor-based GraphQL connections (with hasNextPage, endCursor, edges) are planned for a future version of the API. The current offset-based approach is simpler but less efficient for large datasets. The migration will be backward-compatible — limit/offset will continue to work.