TwitterViewer 0.1.0

dotnet add package TwitterViewer --version 0.1.0
                    
NuGet\Install-Package TwitterViewer -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TwitterViewer" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TwitterViewer" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="TwitterViewer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TwitterViewer --version 0.1.0
                    
#r "nuget: TwitterViewer, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TwitterViewer@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TwitterViewer&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=TwitterViewer&version=0.1.0
                    
Install as a Cake Tool

TwitterViewer .NET SDK

.NET client for the TwitterViewer API: read public X (Twitter) posts, threads, profiles and replies as JSON, Markdown, text or PDF. All access is read-only. TwitterViewer is an independent service, not the official X API.

Targets .NET 8 and .NET Standard 2.0. Uses only System.Net.Http and System.Text.Json.

Install

dotnet add package TwitterViewer

Quickstart

The API needs a Plus plan: every call from an account without it fails with 402 LIMIT_REACHED and details.reason = PLUS_REQUIRED (API, MCP and CLI access are all part of Plus). Create an API key at twitterviewer.ai/account/api and export it as TWITTERVIEWER_API_KEY.

using System;
using TwitterViewer;

var client = new TwitterViewerClient();

var result = await client.ConvertAsync("https://x.com/jack/status/20");

Console.WriteLine(result.Markdown);
Console.WriteLine($"{result.Credits.Remaining} credits left");

Configuration

var client = new TwitterViewerClient(new TwitterViewerClientOptions
{
    ApiKey = "tv_live_...",                           // default: TWITTERVIEWER_API_KEY
    BaseUrl = new Uri("https://twitterviewer.ai"),    // default: TWITTERVIEWER_BASE_URL, then this address
    Timeout = TimeSpan.FromSeconds(90),               // default; per attempt, response body included
    MaxRetries = 2,                                   // 0 turns retries off
});

The client is thread-safe. Create one and reuse it.

Dependency injection

Pass your own HttpClient; the SDK does not modify or dispose it. With IHttpClientFactory (Microsoft.Extensions.Http):

services.AddSingleton(new TwitterViewerClientOptions { ApiKey = configuration["TwitterViewer:ApiKey"] });
services.AddHttpClient<TwitterViewerClient>();

A supplied HttpClient applies its own Timeout (100 seconds by default) on top of TwitterViewerClientOptions.Timeout (90 seconds by default); the shorter one applies. If it has a BaseAddress and BaseUrl is not set, requests go to that address.

Methods

Every method takes an optional CancellationToken.

Method API operation Returns
ConvertAsync(url, options?) POST /api/v1/convert ConvertResult
ConvertByQueryAsync(url, options?) GET /api/v1/convert ConvertResult
ConvertDocumentAsync(url, options?) POST /api/v1/convert RenderedDocument
ConvertPdfAsync(url, options?) POST /api/v1/convert RenderedDocument
GetRepliesAsync(postUrl, max?) GET /api/v1/replies RepliesResult
GetCreditsAsync() GET /api/v1/credits CreditBalance
SwapProfileAsync(handle, options?) GET /api/v1/swap/{handle} RenderedDocument
SwapPostAsync(handle, id, options?) GET /api/v1/swap/{handle}/status/{id} RenderedDocument

Convert a post, thread or profile

url is a link to an X post or profile (x.com or twitter.com), or an @handle.

var thread = await client.ConvertAsync("https://x.com/jack/status/20");

var profile = await client.ConvertAsync("@NASA", new ConvertOptions
{
    Max = 50,                  // profile links only: 1 to 200, default 20
    IncludeReplies = false,
    IncludeReposts = false,
});

foreach (var post in profile.Posts)
{
    Console.WriteLine($"{post.CreatedAt:u} {post.Text}");
}

if (profile.Author is User author)
{
    Console.WriteLine(author.Followers);
}

Options for post links: Scope = ConvertScope.Thread (default, the author's connected posts), ConvertScope.Post or ConvertScope.Conversation (thread plus the first page of replies). Stats controls the engagement numbers in the rendered document, and Format = ConvertFormat.Obsidian makes Markdown hold Obsidian Markdown.

ConvertByQueryAsync takes the same arguments and sends them as a query string:

var result = await client.ConvertByQueryAsync("https://x.com/jack/status/20");

Get the document body

var document = await client.ConvertDocumentAsync(
    "https://x.com/jack/status/20",
    new ConvertOptions { Format = ConvertFormat.Text });   // default: Markdown

Console.WriteLine(document.AsString());
Console.WriteLine(document.PostsReturned);

PDF

var pdf = await client.ConvertPdfAsync(
    "https://x.com/jack/status/20",
    new ConvertOptions { Paper = PaperSize.Letter });

await File.WriteAllBytesAsync(pdf.FileName ?? "thread.pdf", pdf.Content);

Replies

max is 20 by default, up to 100.

var replies = await client.GetRepliesAsync("https://x.com/jack/status/20", max: 50);

Credit balance

Costs no credits.

var balance = await client.GetCreditsAsync();
Console.WriteLine(balance.Unlimited ? "unlimited" : balance.Total.ToString());

Domain swap

The same conversion, addressed like an X link. The body is Markdown unless you set another format.

var posts = (await client.SwapProfileAsync("NASA")).AsString();

var document = await client.SwapPostAsync("jack", "20", new ConvertOptions { Format = ConvertFormat.Json });
var post = document.ToConvertResult();

Errors and retries

Exception When Useful members
TwitterViewerApiException The server answered with an error status Status, Code, RawCode, Message, RetryAfterSeconds, Details, Reason
TwitterViewerConnectionException Connection failure or timeout IsTimeout
OperationCanceledException You cancelled the token

The first two extend TwitterViewerException. Branch on Code and Reason, not on the message.

try
{
    await client.ConvertPdfAsync("@NASA");
}
catch (TwitterViewerApiException e) when (e.Code == TwitterViewerErrorCode.LimitReached)
{
    // PLUS_REQUIRED or INSUFFICIENT_CREDITS
    Console.Error.WriteLine(e.Reason);
}

Retries (MaxRetries, default 2):

  • Retried: connection failures, timeouts, dropped connections, 429, and 5xx (including gateway error pages).
  • Not retried: 402, every other 4xx, and 501.
  • The client waits for the server's retryAfterSec when given, and otherwise backs off exponentially with jitter (up to 0.5 s, then 1 s, 2 s, at most 8 s). If retryAfterSec is longer than 120 seconds the exception is thrown right away, so you can decide when to try again.

Retrying is safe: the same request from the same account within 10 minutes returns the first result and is not charged again. If an identical request is still running, the server waits for it; after a minute it answers 503 with the reason IN_PROGRESS and a retryAfterSec, which the client retries like any other 503.

Rate limits are counted per account: 30 requests a minute.

Credits

1 credit = 1 post returned. A quoted post counts as one more post; author profile data is free.

  • A request repeated by the same account within 10 minutes returns the first result and is not charged again. Same request means:
    • conversions: the same link (case-insensitive) with the same scope, max, replies and reposts. Changing the format or stats does not matter, except that PDF is tracked separately.
    • replies: the same post id and max.
  • If that result was partial (limited by the balance, or a free website preview of a conversion) and the account now has credits, the request is treated as new and charged.
  • Replies return only as many posts as the balance covers.
  • Errors and empty results are free. With a zero balance, billable calls fail with 402; a repeat within the 10 minutes still returns the earlier result.

Development

Needs the .NET 10 SDK or newer.

dotnet test --solution TwitterViewer.slnx
dotnet test --solution TwitterViewer.slnx -p:TestNetStandard=true   # the netstandard2.0 build
dotnet pack src/TwitterViewer/TwitterViewer.csproj -c Release -o artifacts

Tests use a fake HttpMessageHandler. The integration tests run only when both variables are set, and they spend credits:

TWITTERVIEWER_BASE_URL=http://localhost:3400 TWITTERVIEWER_API_KEY=tv_live_... dotnet test --solution TwitterViewer.slnx

openapi.json is the contract. A test fails when it differs from ../openapi.json (skipped if that file is absent) or when an operation, model property, option or error code has no counterpart in the SDK.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 0 12/3/2026