Modrinth.Net

June 9, 2026 · View on GitHub

GitHub Nuget Nuget (with prereleases) Modrinth API

C# Wrapper for the Modrinth API

Main attributes

  • Automatic rate limiting
    • Retry count is configurable
  • No dependencies
  • Fully documented
  • Support for .NET 8.0 and newer

AOT / source-generated JSON

For Native AOT or trimmed deployments, pass a JsonSerializerContext via ModrinthClientConfig.JsonSerializerContext. The context is merged into the serializer's type resolver chain, so you only need to declare types for the endpoints you actually use.

using System.Text.Json.Serialization;
using Modrinth;
using Modrinth.Models;

// Declare a source-generated context for the endpoints you use
[JsonSerializable(typeof(SearchResponse))]
[JsonSerializable(typeof(SearchResult[]))]
internal partial class MyModrinthContext : JsonSerializerContext;

var client = new ModrinthClient(new ModrinthClientConfig
{
    UserAgent = "MyAwesomeProject",
    JsonSerializerContext = MyModrinthContext.Default
});

var results = await client.Project.SearchAsync("sodium");
Console.WriteLine(results.Hits[0].Title);

Usage

using Modrinth;

var options = new ModrinthClientConfig 
{
    // Optional, if you want to access authenticated API endpoints
    ModrinthToken = "Your_Authentication_Token",
    // For Modrinth API, you must specify a user-agent
    // There is a default library user-agent, but it is recommended to specify your own
    UserAgent = "MyAwesomeProject"
};

var client = new ModrinthClient(options);

var project = await client.Project.GetAsync("sodium");

Console.WriteLine(project.Description);

But you don't have to provide options at all, you can just create a client with the default options:

var client = new ModrinthClient();

User-Agent

  • You can also use the UserAgent class to help you create a valid user-agent
  • User-Agent currently cannot be changed after the client has been created
  • More info about the User-Agent can be found here
using Modrinth;

// Note: All properties are optional, and will be ignored if they are null or empty
var userAgent = new UserAgent
{
    ProjectName = "ProjectName",
    ProjectVersion = "1.0.0",
    GitHubUsername = "Username",
    Contact = "contact@contact.com"
};

var options = new ModrinthClientOptions
{
    UserAgent = userAgent.ToString()
};

var client = new ModrinthClient(options);
  • You can search for projects using the SearchAsync method, in the Project endpoint
using Modrinth;

var client = new ModrinthClient(userAgent: "My_Awesome_Project");

var search = await client.Project.SearchAsync("sodium");

foreach (var project in search.Hits)
{
    Console.WriteLine(project.Title);
}

Search with facets/filtering

  • You can filter the search results by using facets, which are a way to filter the results by certain criteria
  • You can read more about facets here
  • You can create a FacetCollection and add facets to it, and then pass it to the SearchAsync method

Example:

// For search with facets, you first need to create a FacetCollection
var facets = new FacetCollection();

// Then you can add facets to it
// You add a facet by calling the Add method on the FacetCollection
// In one call, you can add multiple facets, they will be combined in an OR statement
// If you call Add again, the new facets will be combined in an AND statement with the previous ones

// Example:
facets.Add(Facet.Category("adventure"), Facet.Category("magic"));
facets.Add(Facet.Version("1.19.4"));

// This will create a query that looks like this:
// (category:adventure OR category:magic) AND version:1.19.4
// Basically it will search for projects that have the category "adventure" or "magic" on Minecraft version 1.19.4

// Then you can pass the FacetCollection to the SearchAsync method
var search = await _client.Project.SearchAsync("", facets: facets);

As FacetCollection implements ICollection<T>, you can use collection initializers to add facets to it, like this:

var facets = new FacetCollection
{
    { Facet.Category("adventure"), Facet.Category("magic") },
    { Facet.Version("1.19.4") }
};

Which will create the same query as the previous example.

Unsuccesful API calls

  • If the API call was unsuccessful, the client will throw an ModrinthApiException exception
  • This will be thrown if the API call return non-200 status code
using Modrinth;
using Modrinth.Exceptions;
using System.Net;

var client = new ModrinthClient(userAgent: "My_Awesome_Project");

try 
{
    var project = await _client.Project.GetAsync("non-existent-project");
    
    Console.WriteLine(project.Title);
}
// You can catch the exception and only handle the 404 status code
catch (ModrinthApiException e) when (e.Response.StatusCode == HttpStatusCode.NotFound) 
{
    Console.WriteLine("Project not found");
}
// Or you can catch the exception and handle all non-200 status codes
catch (ModrinthApiException e)
{
    Console.WriteLine($"API call failed with status code {e.Response.StatusCode}");
}

List of endpoints and their support in this library

IconMeaningComment
Implemented
Not implemented
⚠️UntestedThe endpoint has been implemented, but no tests have been written for it yet

Project endpoints

NameMethodImplemented
Search projectsGET
Get a projectGET
Modify a projectPATCH
Delete a projectDELETE⚠️
Get multiple projectsGET
Bulk-edit multiple projectsPATCH
Get a list of random projectsGET
Create a projectPOST
Change project's iconPATCH
Delete project's iconDELETE
Check project slug/ID validityGET
Add a gallery imagePOST
Modify a gallery imagePATCH
Delete a gallery imageDELETE
Get all of a project's dependenciesGET
Follow a projectPOST
Unfollow a projectDELETE
Schedule a projectPOST

Version endpoints

NameMethodImplemented
List project's versionsGET
Get a versionGET
Modify a versionPATCH
Delete a versionDELETE⚠️
Get a version given a version number or IDGET
Create a versionPOST
Schedule a versionPOST⚠️
Get multiple versionsGET
Add files to versionPOST

Version file endpoints

NameMethodImplemented
Get version from hashGET✅️
Delete a file from its hashDELETE⚠️
Latest version of a project from a hash, loader(s), and game version(s)POST✅️
Get versions from hashesPOST✅️
Latest versions of multiple projects from hashes, loader(s), and game version(s)POST✅️

User endpoints

NameMethodImplemented
Get a userGET
Modify a userPATCH
Get user from authorization headerGET
Get multiple usersGET
Change user's avatarPATCH
Get user's projectsGET
Get user's followed projectsGET
Get user's payout historyGET
Withdraw payout balance to PayPal or VenmoPOST

Threads endpoints

🔐 All of the endpoints in this section require authentication.

NameMethodImplemented
Report a project, user, or versionPOST
Get your open reportsGET
Get report from IDGET
Modify a reportPATCH
Get multiple reportsGET
Get a threadGET
Send a text message to a threadPOST
Get multiple threadsGET
Delete a threadDELETE

Notifications endpoints

🔐 All of the endpoints in this section require authentication.

NameMethodImplemented
Get user's notificationsGET
Get notification from IDGET
Mark notification as readPATCH
Delete a notificationDELETE
Get multiple notificationsGET
Mark multiple notifications as readPATCH
Delete multiple notificationsDELETE

Team endpoints

NameMethodImplemented
Get a project's team membersGET
Get a team's membersGET
Add a user to a teamPOST⚠️
Get the members of multiple teamsGET
Join a teamPOST⚠️
Modify a team member's informationPATCH⚠️
Remove a member from a teamDELETE⚠️
Transfer team's ownership to another userPATCH⚠️

Tag endpoints

NameMethodImplementedComment
Get a list of categoriesGET
Get a list of loadersGET
Get a list of game versionsGET
Get the text and title of a licenseGET
Get a list of donation platformsGET
Get a list of report typesGET
Get a list of project typesGET
Get a list of side typesGET

Miscellaneous endpoints

NameMethodImplemented
Forge Updates JSON fileGET
Various statistics about this Modrinth instanceGET

Development

Testing

Library uses NUnit for testing.

To run tests, you can use the dotnet test command. To run authenticated tests, you need to set the ModrinthApiKey secret for the test project.

You can do this by running the following command in the terminal, in the root of the project:

dotnet user-secrets init --project .\test\Modrinth.Net.Test
dotnet user-secrets set ModrinthApiKey "Your_Authentication_Token" --project .\test\Modrinth.Net.Test

If you wish to remove the secret you can run:

dotnet user-secrets remove ModrinthApiKey --project .\test\Modrinth.Net.Test

Optionally, you can also set the MODRINTH_API_KEY environment variable, but secrets are preferred.

Disclaimer

This is not an official Modrinth project. This is a third-party project that is not affiliated with Modrinth in any way.