TMDB API C# tutorial for .NET 8

The TMDB API works from C# with only HttpClient and System.Text.Json on .NET 8, so no NuGet package is needed. This tutorial builds a console app that searches a title and loads its details and ratings in 2 requests, retries on 429, caches replies in files and takes about 15 minutes.

.cs C# Updated View as Markdown

To call the TMDB API from C#, create one HttpClient with a base address and a Bearer header, then read the JSON with System.Text.Json. A lookup in this tutorial takes 2 requests, one search and one details call with ratings, and the finished app is a single Program.cs of under 150 lines. The code calls amodb, an independent paid API that keeps the TMDB v3 paths, parameters and JSON, so a client written for TMDB only needs a new base address and key.

What do you need to call the TMDB API from C#?

You build MovieLookup, a console app that takes a title on the command line, searches, loads the best match with its ratings and prints a short card with a poster link.

You needValue
Runtime.NET 8 SDK, on Windows, macOS or Linux
PackagesNone. HttpClient and System.Text.Json ship with .NET 8
KeyAn amodb key, 32 lowercase hex characters. The TMDB API key page shows how to get one
PlanAny plan. Lite, at 20 requests per minute, is enough
Where the key livesThe environment variable AMODB_KEY
TimeAbout 15 minutes

Which calls does the C# app make, and what do they cost?

Every call to the API costs 1 request, and cached replies from the edge count too. Posters come from a separate host that needs no key and is not counted.

CallPathCostYour file cache
SearchGET search/movie?query={title}&language=en-US1 request10 minutes
Details with ratingsGET movie/{id}?language=en-US&append_to_response=ratings1 request6 hours
PosterGET https://img.amodb.dev/t/p/w342{poster_path}0 requestsnone

One lookup is 2 requests, and a title already in the file cache costs none. At 20 requests per minute that is 10 new lookups a minute, and an account can never pass 28,800 requests a day on that plan. The append_to_response=ratings parameter merges the five rating sources into the details reply, so ratings need no third call. The movie details API page lists the other values you can append.

Step 1: Get an API key

Buy a plan on amodb pricing with your email, sign in with the 6 digit code amodb then emails you, copy the first key, which is shown once, and test it with one call.

Every plan has every TMDB v3 compatible endpoint, images, 14 languages and the extensions. The plans differ in rate (Lite 20, Pro 40, Pro+ 120 requests per minute, from $5.19 a month), and only Pro+ also has the all in one endpoint GET /3/all/{movie|tv|person}/{id}. There is no free tier or trial. If you want to check that the service is reachable first, the public https://api.amodb.dev/plans endpoint needs no key. The key is a string of 32 lowercase hex characters. Export it and test it with one call:

A 200 means the key works. A 401 means the key is wrong or missing. In PowerShell set the variable with $env:AMODB_KEY = "YOUR_API_KEY". The authentication page covers the api_key query parameter as an alternative to the header.

Shell
export AMODB_KEY=YOUR_API_KEY
curl -s -o /dev/null -w "%{http_code}\n" \
  -H "Authorization: Bearer $AMODB_KEY" \
  "https://api.amodb.dev/3/movie/550"

Step 2: Create the project

Create a console project named MovieLookup that targets .NET 8 and open its folder.

The .NET 8 template turns on implicit usings and nullable reference types. That already imports System, System.IO, System.Linq and System.Net.Http. You add the other using lines in the file.

Shell
dotnet new console -n MovieLookup -f net8.0
cd MovieLookup

Step 3: Send the first request

Create one HttpClient with the base address https://api.amodb.dev/3/, a 10 second timeout and the Bearer header, then send a search request.

End the base address with a slash and write relative paths without a leading slash. A leading slash would replace the /3 part of the base path.

Run it with dotnet run. It prints 200 when the key works and the search succeeds. Reuse the same HttpClient for every call in the program, because a new instance for each request opens new connections.

C#
using System.Net.Http.Headers;

using var http = new HttpClient
{
    BaseAddress = new Uri("https://api.amodb.dev/3/"),
    Timeout = TimeSpan.FromSeconds(10),
};
http.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("AMODB_KEY"));

var response = await http.GetAsync("search/movie?query=fight%20club&language=en-US");
Console.WriteLine((int)response.StatusCode);

Step 4: Parse the JSON into records

Declare records for the search reply and the movie, and use JsonNamingPolicy.SnakeCaseLower (new in .NET 8) so names such as release_date map to PascalCase members.

The response uses snake case names, and fields you do not declare are ignored.

The ratings object appears because the details call adds append_to_response=ratings. Each of its five sources is an object with value and votes, or null when the score is missing. votes can be null too: the live reply for Fight Club has no vote count for Kinopoisk, Metacritic or Rotten Tomatoes. The movie details API page lists every other field.

SourceScaleCan be null
imdb0 to 10yes
kinopoisk0 to 10yes
tmdb0 to 10yes
metacritic0 to 100yes
rotten_tomatoes0 to 100yes

Treat null as unknown and never as zero. The movie ratings API page explains each source and its null rules.

C#
record SearchResponse(List<SearchHit> Results);
record SearchHit(int Id, string Title, string? ReleaseDate);
record Movie(int Id, string Title, string? Tagline, string? ReleaseDate, int? Runtime,
    string? PosterPath, double VoteAverage, RatingSet? Ratings);
record RatingSet(Score? Imdb, Score? Kinopoisk, Score? Metacritic, Score? RottenTomatoes, Score? Tmdb);
record Score(double Value, int? Votes);

Step 5: Handle errors and rate limits

Wrap each call in a loop that reacts to the HTTP status code, stopping on 401 and retrying on 429.

StatusMeaningWhat the app does
401Key missing or invalid (status_code 7 for an invalid key)Print a message and stop, a retry cannot help.
402The plan period has ended (status_code 36)Print a message and stop. Renew on amodb pricing.
404No record for that idReport it and exit.
429Over your requests per minute (status_code 25)Wait Retry-After seconds, capped at 30, and retry at most twice.
500 or 504Server side failureReport the status and run the command again later.

Network failures surface as HttpRequestException, and a timeout surfaces as TaskCanceledException. Catch both at the top level. Every keyed reply also carries X-RateLimit-Remaining, so a long job can slow down before it reaches a 429. The error body uses the TMDB shape {"success": false, "status_code": N, "status_message": "..."}. See TMDB API rate limit and error codes for the full lists.

C#
for (var attempt = 0; ; attempt++)
{
    using var response = await http.GetAsync(path);
    if (response.StatusCode == HttpStatusCode.TooManyRequests && attempt < 2)
    {
        var seconds = Math.Min(response.Headers.RetryAfter?.Delta?.TotalSeconds ?? 5, 30);
        await Task.Delay(TimeSpan.FromSeconds(seconds));
        continue;
    }
    if (response.StatusCode == HttpStatusCode.Unauthorized)
        throw new AmodbException("The API key was rejected (401). Check AMODB_KEY.");
    // ...handle other statuses, then read the body
}

Step 6: Cache responses on disk

Save each reply in a file in the temp folder and reuse it while it is younger than the lifetime the edge uses, 10 minutes for search and 6 hours for details.

The rate limit check runs before the edge cache, so an answer served from the edge still counts toward your requests per minute. A cache in your own program is the only way to save requests. The edge keeps details for 6 hours and search results for 10 minutes, so the app uses the same lifetimes. A file in the temp folder is fresh when its write time is inside the TTL. A cache hit costs 0 requests.

The cache key is the SHA-256 hash of the request path, so two different searches never share a file. Delete the amodb-cache folder in your temp directory to clear it.

C#
class FileCache
{
    readonly string dir = Path.Combine(Path.GetTempPath(), "amodb-cache");

    string PathFor(string key) =>
        Path.Combine(dir, Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(key))) + ".json");

    public string? Get(string key, TimeSpan ttl)
    {
        var file = PathFor(key);
        return File.Exists(file) && DateTime.UtcNow - File.GetLastWriteTimeUtc(file) < ttl
            ? File.ReadAllText(file)
            : null;
    }
}

Step 7: Put it together

Replace Program.cs with the complete listing below, which adds the Set method to the cache and the AmodbClient class that combines the cache, the retry loop and the JSON options.

C#
using System.Globalization;
using System.Net;
using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;

CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; // same number format on every machine

var key = Environment.GetEnvironmentVariable("AMODB_KEY");
if (string.IsNullOrWhiteSpace(key))
{
    Console.Error.WriteLine("Set AMODB_KEY first.");
    return 1;
}

var title = string.Join(' ', args).Trim();
if (title.Length == 0)
{
    Console.Error.WriteLine("Usage: dotnet run -- \"movie title\"");
    return 1;
}

using var http = new HttpClient
{
    BaseAddress = new Uri("https://api.amodb.dev/3/"),
    Timeout = TimeSpan.FromSeconds(10),
};
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", key);
var client = new AmodbClient(http, new FileCache());

try
{
    var search = await client.GetAsync<SearchResponse>(
        $"search/movie?query={Uri.EscapeDataString(title)}&language=en-US", TimeSpan.FromMinutes(10));
    var hit = search.Results.FirstOrDefault();
    if (hit is null)
    {
        Console.WriteLine($"No movie found for \"{title}\".");
        return 0;
    }

    var movie = await client.GetAsync<Movie>(
        $"movie/{hit.Id}?language=en-US&append_to_response=ratings", TimeSpan.FromHours(6));
    Print(movie);
    return 0;
}
catch (AmodbException ex)
{
    Console.Error.WriteLine(ex.Message);
    return 1;
}
catch (HttpRequestException ex)
{
    Console.Error.WriteLine($"Network error: {ex.Message}");
    return 1;
}
catch (TaskCanceledException)
{
    Console.Error.WriteLine("The request timed out after 10 seconds.");
    return 1;
}

static void Print(Movie m)
{
    var year = m.ReleaseDate is { Length: >= 4 } d ? d[..4] : "n/a";
    Console.WriteLine($"{m.Title} ({year}), {m.Runtime?.ToString() ?? "?"} min");
    if (!string.IsNullOrEmpty(m.Tagline)) Console.WriteLine(m.Tagline);
    Console.WriteLine($"IMDb: {Describe(m.Ratings?.Imdb)}");
    Console.WriteLine($"TMDB: {Describe(m.Ratings?.Tmdb)}");
    if (m.PosterPath is not null)
        Console.WriteLine($"Poster: https://img.amodb.dev/t/p/w342{m.PosterPath}");
}

static string Describe(Score? s) =>
    s is null ? "not known" : $"{s.Value:0.0}" + (s.Votes is { } v ? $" ({v:N0} votes)" : "");

record SearchResponse(List<SearchHit> Results);
record SearchHit(int Id, string Title, string? ReleaseDate);
record Movie(int Id, string Title, string? Tagline, string? ReleaseDate, int? Runtime,
    string? PosterPath, double VoteAverage, RatingSet? Ratings);
record RatingSet(Score? Imdb, Score? Kinopoisk, Score? Metacritic, Score? RottenTomatoes, Score? Tmdb);
record Score(double Value, int? Votes);

class AmodbException : Exception
{
    public AmodbException(string message) : base(message) { }
}

class FileCache
{
    readonly string dir = Path.Combine(Path.GetTempPath(), "amodb-cache");

    string PathFor(string key) =>
        Path.Combine(dir, Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(key))) + ".json");

    public string? Get(string key, TimeSpan ttl)
    {
        var file = PathFor(key);
        return File.Exists(file) && DateTime.UtcNow - File.GetLastWriteTimeUtc(file) < ttl
            ? File.ReadAllText(file)
            : null;
    }

    public void Set(string key, string json)
    {
        Directory.CreateDirectory(dir);
        File.WriteAllText(PathFor(key), json);
    }
}

class AmodbClient(HttpClient http, FileCache cache)
{
    static readonly JsonSerializerOptions Options = new()
    {
        PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
    };

    public async Task<T> GetAsync<T>(string path, TimeSpan ttl)
    {
        var cached = cache.Get(path, ttl);
        if (cached is not null) return JsonSerializer.Deserialize<T>(cached, Options)!;

        for (var attempt = 0; ; attempt++)
        {
            using var response = await http.GetAsync(path);
            if (response.StatusCode == HttpStatusCode.TooManyRequests && attempt < 2)
            {
                var seconds = Math.Min(response.Headers.RetryAfter?.Delta?.TotalSeconds ?? 5, 30);
                await Task.Delay(TimeSpan.FromSeconds(seconds));
                continue;
            }
            if (response.StatusCode == HttpStatusCode.Unauthorized)
                throw new AmodbException("The API key was rejected (401). Check AMODB_KEY.");
            if (!response.IsSuccessStatusCode)
                throw new AmodbException($"amodb returned status {(int)response.StatusCode}.");

            var body = await response.Content.ReadAsStringAsync();
            cache.Set(path, body);
            return JsonSerializer.Deserialize<T>(body, Options)!;
        }
    }
}

Run it with a title. This is the output for the first search hit, movie 550. Vote counts grow over time, so yours will differ a little.

The TMDB line shows 8.4 because the code prints one decimal of the 8.437 in ratings.tmdb.value. The poster host img.amodb.dev needs no key, so you can pass the poster URL straight to a browser or an image control. See the TMDB image URL page for the size list.

Shell
dotnet run -- "fight club"
# Fight Club (1999), 139 min
# Mischief. Mayhem. Soap.
# IMDb: 8.8 (2,669,989 votes)
# TMDB: 8.4 (33,039 votes)
# Poster: https://img.amodb.dev/t/p/w342/jSziioSwPVrOy9Yow3XhWIBDjq1.jpg

How do I move an existing TMDB v3 client to this API?

Change two values, the base address and the key, and keep your models and calls.

TMDBamodb
Base addresshttps://api.themoviedb.org/3/https://api.amodb.dev/3/
KeyYour TMDB keyAn amodb key, same shape: 32 lowercase hex characters
Send the keyapi_key or a Bearer headerapi_key or a Bearer header
Poster hostTMDB's own image hosthttps://img.amodb.dev/t/p/{size}/{file}, no key needed

Read the base address from configuration and not from a constant, so a test build can point at a different host. amodb also returns extras that TMDB does not, such as ratings, moods, soundtracks, wikidata and showtimes, all reachable with append_to_response. TMDB write methods for accounts, sessions, ratings and lists return HTTP 405, and aggregate_credits and the changes paths are not offered.

Is the TMDB API free to use in a C# project?

The TMDB API is free only while your app earns nothing, and a commercial C# project needs a paid plan from TMDB or another provider.

TMDB staff said on the TMDB forum (2026-10-15) that an app counts as commercial the moment it earns revenue from ads, in-app purchases, donations or subscriptions. They quoted the commercial plan at $149 a month for companies under $1M revenue, with a custom quote above (2026-03-31), and there is no small tier between free and $149. TMDB's terms of use say TMDB decides what counts as commercial, require its logo with a not-endorsed notice and limit caching to 6 months.

ProjectTMDBamodb
Personal, earns nothingFree under TMDB's termsPaid, from $5.19 a month, no free tier
Commercial (ads, subscriptions, sales)$149 a month under $1M revenue, custom quote aboveFrom $5.19 a month, no extra charge; the terms do not prohibit it
Logo or attributionTMDB logo and notice requiredNo amodb logo; credit JustWatch and licensed texts and images as marked

amodb plans cost $5.19, $6.19 or $7.19 a month, which is 3.5% to 4.8% of $149. Longer periods save up to 40 percent, so the lowest price is $3.11 a month for Lite on 24 months ($74.74). Pay by card, Apple Pay or Google Pay, prepaid for 1, 3, 6, 12 or 24 months; those payments do not renew automatically. Patreon is monthly and renews on Patreon until the member cancels there. Do not resell raw API access, share keys or put keys in client side code. For the longer answer to Is the TMDB API free?, read the comparison, and see the TMDB API alternative page for other options.

Next steps