Introduction
During Pixiv crawler development, I investigated multiple Pixiv API endpoints in depth. This document summarizes commonly used APIs, request formats, and response structures from practical implementation work.
I also built a serverless Pixiv crawler recently:
Example project:
https://github.com/evepupil/serverless_pixiv_crawlergithub.com/evepupil/serverless_pixiv_crawler
Basic configuration
Request headers
All API calls require proper headers, especially Cookie and User-Agent:
interface PixivHeaders { 'User-Agent': string; cookie: string; Referer: string; 'Accept-Language': string;}Common response format
Most Pixiv APIs follow this structure:
{ "error": false, "body": { // payload }}Core API endpoints
1. Get illustration details
Endpoint: https://www.pixiv.net/ajax/illust/{pid}
Method: GET
Parameters:
pid: illustration ID (required)
Response structure:
interface PixivIllustInfo { body: { userId: string; // author user ID title: string; // illustration title userName: string; // author username tags: { tags: Array<{ tag: string; // tag name translation?: { en: string; // english translation }; }>; }; likeCount: number; // likes bookmarkCount: number; // bookmarks viewCount: number; // views illusts?: Array<{ id: string }>; // related illustrations recommendUsers?: Array<{ userId: string; illustIds: string[]; }>; }; error: boolean;}Example:
const response = await axios.get( `https://www.pixiv.net/ajax/illust/123456789`, { headers: pixivHeaders });const illustInfo: PixivIllustInfo = response.data;2. Get illustration pages (image URLs)
Endpoint: https://www.pixiv.net/ajax/illust/{pid}/pages?lang=zh
Method: GET
Parameters:
pid: illustration ID (required)lang: language (defaultzh)
Response structure:
interface PixivIllustPagesResponse { body: Array<{ urls: { original: string; // original image regular: string; // regular size small: string; // small size thumb_mini: string; // thumbnail }; }>; error: boolean;}Example:
const response = await axios.get( `https://www.pixiv.net/ajax/illust/123456789/pages?lang=zh`, { headers: pixivHeaders });const pagesInfo: PixivIllustPagesResponse = response.data;3. Get illustration recommendations
Endpoint: https://www.pixiv.net/ajax/illust/{pid}/recommend/init?limit=30&lang=zh
Method: GET
Parameters:
pid: illustration ID (required)limit: number of results (default 30)lang: language (defaultzh)
Response structure:
interface PixivRecommendResponse { body: { illusts: Array<{ id: string }>; // recommended illustration IDs }; error: boolean;}Example:
const response = await axios.get( `https://www.pixiv.net/ajax/illust/123456789/recommend/init?limit=30&lang=zh`, { headers: pixivHeaders });const recommendInfo: PixivRecommendResponse = response.data;4. Get user recommendations
Endpoint: https://www.pixiv.net/ajax/user/{userId}/recommends?userNum=30&workNum=5&isR18=false&lang=zh
Method: GET
Parameters:
userId: user ID (required)userNum: number of recommended users (default 30)workNum: number of works per user (default 5)isR18: include R18 content (default false)lang: language (defaultzh)
Response structure:
interface PixivUserRecommendResponse { body: { recommendUsers: Array<{ userId: string; // recommended user ID illustIds: string[]; // this user's illustration IDs }>; }; error: boolean;}Example:
const response = await axios.get( `https://www.pixiv.net/ajax/user/123456/recommends?userNum=30&workNum=5&isR18=false&lang=zh`, { headers: pixivHeaders });const userRecommendInfo: PixivUserRecommendResponse = response.data;Ranking endpoint
Fetch ranking data
Endpoint: https://www.pixiv.net/ranking.php?mode={mode}&content=illust
Method: GET
Parameters:
mode: ranking typedaily: daily rankingweekly: weekly rankingmonthly: monthly rankingcontent: fixed asillust
Note: this endpoint returns HTML, so you need regex parsing to extract IDs.
Parsing example:
// Regex for illustration IDsconst pidRegex = /<a\s+[^>]*href=["']\/artworks\/(\d+)["'][^>]*>/g;const pids: string[] = [];let match: RegExpExecArray | null;
while ((match = pidRegex.exec(html)) !== null) { pids.push(match[1]);}Homepage recommendations
Fetch homepage recommendation content
Endpoint: https://www.pixiv.net/
Method: GET
Notes: homepage recommendations are also parsed from HTML, usually by locating elements with the data-gtm-work-id attribute.
Parsing example:
// Regex for recommended illustration IDsconst pidRegex = /data-gtm-work-id=["'](\d+)["']/gi;const pids: string[] = [];let match: RegExpExecArray | null;
while ((match = pidRegex.exec(html)) !== null) { pids.push(match[1]);}Error handling
Common error types
- 404: illustration does not exist or was deleted
- 403: insufficient permission or login required
- 429: rate limit exceeded
Error handling example
try { const response = await axios.get(apiUrl, { headers }); return response.data;} catch (error) { if (error.response?.status === 404) { console.log('Illustration not found'); return { error: true, status: 404, message: 'Image not found' }; } throw error;}Best practices
1. Request rate control
// Add random delay to reduce ban riskconst delay = Math.random() * 2000 + 1000; // random 1-3sawait new Promise(resolve => setTimeout(resolve, delay));2. Header rotation
// Rotate among multiple header setsconst headersList: PixivHeaders[] = [ { /* headers set 1 */ }, { /* headers set 2 */ }, { /* headers set 3 */ }];
let headerIndex = 0;const currentHeaders = headersList[headerIndex % headersList.length];headerIndex++;3. Retry mechanism
async function requestWithRetry(url: string, maxRetries: number = 3) { for (let i = 0; i < maxRetries; i++) { try { const response = await axios.get(url, { headers }); return response.data; } catch (error) { if (i === maxRetries - 1) throw error; await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1))); } }}Summary
This article, based on a production crawler implementation, summarizes the most useful Pixiv endpoints:
- Illustration info: details, page URLs, recommendations
- User-related data: recommended users and author metadata
- Ranking data: daily / weekly / monthly ranking pages
- Homepage recommendation parsing
When using these APIs:
- Follow website terms of use
- Control request frequency to avoid excessive load
- Handle errors properly
- Use proper headers and authentication context
Hope this reference helps developers working with Pixiv data.
Note: for learning and research only. Please follow applicable laws and platform terms.
