NHentaiAPI 1.8.0
dotnet add package NHentaiAPI --version 1.8.0
NuGet\Install-Package NHentaiAPI -Version 1.8.0
<PackageReference Include="NHentaiAPI" Version="1.8.0" />
paket add NHentaiAPI --version 1.8.0
#r "nuget: NHentaiAPI, 1.8.0"
// Install NHentaiAPI as a Cake Addin #addin nuget:?package=NHentaiAPI&version=1.8.0 // Install NHentaiAPI as a Cake Tool #tool nuget:?package=NHentaiAPI&version=1.8.0
NHentaiAPI
A full nHentai API implementation for .NET
⚠️ If nHentai changes their API format, please create an issue to let me know!
Important Notes
User Agent Requirements
A User-Agent is required to use this API. The client will throw an error if none is provided. You can get your User-Agent by:
- Going to https://www.whatismybrowser.com/detect/what-is-my-user-agent/
- Or by opening Developer Tools (F12) in your browser, going to Network tab, and looking at the "User-Agent" header in any request
Example:
var client = new NHentaiClient("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");
CSRF Token (If Required)
If nHentai implements CSRF protection, you can get the token by:
- Opening Developer Tools (F12)
- Going to Network tab
- Looking for a request header named 'x-csrf-token' or a cookie named 'csrf_token'
- Pass it to the client using the cookies dictionary
Important: The CSRF token must be obtained from the same IP address and User-Agent that will be used with the API. Using a token from a different IP or User-Agent will result in authentication failures.
var cookies = new Dictionary<string, string>
{
{"csrf_token", "your-token-here"}
};
var client = new NHentaiClient("your-user-agent", cookies);
Features
Search Capabilities:
- Browse homepage content
- Search by keywords
- Search by tags with optional popularity sorting
- Filter tags using
-
prefix (exclusion)
Book Operations:
- Fetch book details
- Get related books
Image Operations:
- Page images (preview, thumbnail, and original quality)
- Cover images (preview and thumbnail)
Usage Examples
Search Books:
// Initialize client with User-Agent
var client = new NHentaiClient("your-user-agent-string");
// Search with filters
var result = await client.GetSearchPageListAsync("school swimsuit full color -loli", 2);
// Browse homepage
var homeResults = await client.GetHomePageListAsync(1);
Get Book Details:
var client = new NHentaiClient("your-user-agent-string");
// Get book by ID
var book = await client.GetBookAsync(123);
// Get related books
var related = await client.GetBookRecommendAsync(123);
Get Images:
var book = await client.GetBookAsync(123);
// Get full page image
byte[] picture = await client.GetPictureAsync(book, 1);
// Get cover image
byte[] cover = await client.GetBigCoverPictureAsync(book);
// Get thumbnails
byte[] thumbnail = await client.GetThumbPictureAsync(book, 1);
byte[] coverThumb = await client.GetBookThumbPictureAsync(book);
Check Out My Other Projects
- Mewdeko - Discord Bot
- MartineApi - Image API Wrapper
- NekosBestApi - Anime Image API
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- System.Text.Json (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
[1.8.0]
- Switched to using System.Text.Json instead of Newtonsoft.
- Added proper JSON type handling via converters.
- Updated to .NET 8.0
- Added proper async handling
- Updated thumbnail and image urls to work with nhentais' load balancing urls.