Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

feat(sdks/dotnet): add parse

mogeryb52cf19d51db
diff --git a/apps/.net-sdk/Firecrawl.Tests/ParseTests.cs b/apps/.net-sdk/Firecrawl.Tests/ParseTests.cs
new file mode 100644
index 000000000..12bd2cccc
--- /dev/null
+++ b/apps/.net-sdk/Firecrawl.Tests/ParseTests.cs
@@ -0,0 +1,234 @@
+using System.Net;
+using System.Net.Http.Headers;
+using System.Text;
+using System.Text.Json;
+using Firecrawl.Exceptions;
+using Firecrawl.Models;
+using Xunit;
+
+namespace Firecrawl.Tests;
+
+public class ParseTests
+{
+ [Fact]
+ public void ParseFile_FromBytes_SetsProperties()
+ {
+ var bytes = Encoding.UTF8.GetBytes("<html><body>ok</body></html>");
+ var file = ParseFile.FromBytes("upload.html", bytes, "text/html");
+
+ Assert.Equal("upload.html", file.Filename);
+ Assert.Equal(bytes, file.Content);
+ Assert.Equal("text/html", file.ContentType);
+ }
+
+ [Fact]
+ public void ParseFile_FromPath_LoadsFile()
+ {
+ var tempPath = Path.Combine(Path.GetTempPath(), $"parse-test-{Guid.NewGuid():N}.html");
+ try
+ {
+ File.WriteAllText(tempPath, "<html>hi</html>", Encoding.UTF8);
+ var file = ParseFile.FromPath(tempPath);
+
+ Assert.Equal(Path.GetFileName(tempPath), file.Filename);
+ Assert.NotEmpty(file.Content);
+ }
+ finally
+ {
+ if (File.Exists(tempPath))
+ File.Delete(tempPath);
+ }
+ }
+
+ [Fact]
+ public void ParseFile_FromPath_ThrowsWhenMissing()
+ {
+ var bogusPath = Path.Combine(Path.GetTempPath(), $"missing-parse-{Guid.NewGuid():N}.html");
+ Assert.Throws<FileNotFoundException>(() => ParseFile.FromPath(bogusPath));
+ }
+
+ [Fact]
+ public void ParseOptions_Serializes_SupportedFields()
+ {
+ var options = new ParseOptions
+ {
+ Formats = new List<object> { "markdown" },
+ OnlyMainContent = true,
+ Timeout = 30000,
+ Proxy = "auto",
+ };
+
+ var json = JsonSerializer.Serialize(options, FirecrawlHttpClient.JsonOptions);
+ Assert.Contains("\"formats\"", json);
+ Assert.Contains("\"onlyMainContent\":true", json);
+ Assert.Contains("\"timeout\":30000", json);
+ Assert.Contains("\"proxy\":\"auto\"", json);
+ }
+
+ [Fact]
+ public void ParseOptions_Validate_RejectsUnsupportedFormats()
+ {
+ var options = new ParseOptions
+ {
+ Formats = new List<object> { "markdown", "screenshot" }
+ };
+
+ var ex = Assert.Throws<ArgumentException>(() => options.Validate());
+ Assert.Contains("screenshot", ex.Message);
+ }
+
+ [Fact]
+ public void ParseOptions_Validate_RejectsUnsupportedProxy()
+ {
+ var options = new ParseOptions { Proxy = "stealth" };
+
+ var ex = Assert.Throws<ArgumentException>(() => options.Validate());
+ Assert.Contains("proxy", ex.Message);
+ }
+
+ [Fact]
+ public void ParseOptions_Validate_RejectsNonPositiveTimeout()
+ {
+ var options = new ParseOptions { Timeout = 0 };
+
+ Assert.Throws<ArgumentException>(() => options.Validate());
+ }
+
+ [Fact]
+ public void ParseOptions_Validate_AllowsSupportedProxy()
+ {
+ var options = new ParseOptions { Proxy = "basic" };
+ options.Validate();
+ }
+
+ [Fact]
+ public async Task ParseAsync_RequiresFile()
+ {
+ var client = new FirecrawlClient(apiKey: "fc-test-key");
+ await Assert.ThrowsAsync<ArgumentNullException>(() => client.ParseAsync(null!));
+ }
+
+ [Fact]
+ public async Task ParseAsync_RejectsEmptyFilename()
+ {
+ var client = new FirecrawlClient(apiKey: "fc-test-key");
+ var file = new ParseFile("", new byte[] { 1, 2, 3 });
+
+ await Assert.ThrowsAsync<ArgumentException>(() => client.ParseAsync(file));
+ }
+
+ [Fact]
+ public async Task ParseAsync_RejectsEmptyContent()
+ {
+ var client = new FirecrawlClient(apiKey: "fc-test-key");
+ var file = new ParseFile("upload.html", Array.Empty<byte>());
+
+ await Assert.ThrowsAsync<ArgumentException>(() => client.ParseAsync(file));
+ }
+
+ [Fact]
+ public async Task ParseAsync_SendsMultipartRequest()
+ {
+ var handler = new CapturingHandler((req, ct) =>
+ {
+ var response = new HttpResponseMessage(HttpStatusCode.OK)
+ {
+ Content = new StringContent(
+ "{\"success\":true,\"data\":{\"markdown\":\"# Parsed\"}}",
+ Encoding.UTF8,
+ "application/json"),
+ };
+ return Task.FromResult(response);
+ });
+
+ var httpClient = new HttpClient(handler);
+ var client = new FirecrawlClient(
+ apiKey: "fc-test-key",
+ apiUrl: "https://api.firecrawl.test",
+ httpClient: httpClient);
+
+ var file = ParseFile.FromBytes(
+ "upload.html",
+ Encoding.UTF8.GetBytes("<html>hi</html>"),
+ "text/html");
+
+ var doc = await client.ParseAsync(file,
+ new ParseOptions { Formats = new List<object> { "markdown" } });
+
+ Assert.NotNull(handler.LastRequest);
+ Assert.Equal(HttpMethod.Post, handler.LastRequest!.Method);
+ Assert.Equal("/v2/parse", handler.LastRequest.RequestUri!.AbsolutePath);
+
+ var contentType = handler.LastRequest.Content!.Headers.ContentType!;
+ Assert.Equal("multipart/form-data", contentType.MediaType);
+
+ var rawBody = await handler.LastRequest.Content.ReadAsStringAsync();
+ Assert.Contains("name=\"options\"", rawBody);
+ Assert.Contains("\"markdown\"", rawBody);
+ Assert.Contains("name=\"file\"", rawBody);
+ Assert.Contains("filename=\"upload.html\"", rawBody);
+ Assert.Contains("<html>hi</html>", rawBody);
+
+ Assert.Equal("# Parsed", doc.Markdown);
+ }
+
+ [Fact]
+ public async Task ParseAsync_PropagatesApiError()
+ {
+ var handler = new CapturingHandler((req, ct) =>
+ {
+ var response = new HttpResponseMessage(HttpStatusCode.BadRequest)
+ {
+ Content = new StringContent(
+ "{\"success\":false,\"error\":\"Unsupported upload type.\"}",
+ Encoding.UTF8,
+ "application/json"),
+ };
+ return Task.FromResult(response);
+ });
+
+ var httpClient = new HttpClient(handler);
+ var client = new FirecrawlClient(
+ apiKey: "fc-test-key",
+ apiUrl: "https://api.firecrawl.test",
+ httpClient: httpClient);
+
+ var file = ParseFile.FromBytes("upload.xyz", new byte[] { 1, 2, 3 });
+
+ var ex = await Assert.ThrowsAsync<FirecrawlException>(
+ () => client.ParseAsync(file));
+ Assert.Contains("Unsupported upload type", ex.Message);
+ }
+
+ private sealed class CapturingHandler : HttpMessageHandler
+ {
+ private readonly Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> _responder;
+
+ public HttpRequestMessage? LastRequest { get; private set; }
+
+ public CapturingHandler(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> responder)
+ {
+ _responder = responder;
+ }
+
+ protected override async Task<HttpResponseMessage> SendAsync(
+ HttpRequestMessage request,
+ CancellationToken cancellationToken)
+ {
+ // Buffer the request body so we can inspect it after SendAsync.
+ if (request.Content != null)
+ {
+ var buffered = await request.Content.ReadAsByteArrayAsync(cancellationToken);
+ var replay = new ByteArrayContent(buffered);
+ foreach (var header in request.Content.Headers)
+ {
+ replay.Headers.TryAddWithoutValidation(header.Key, header.Value);
+ }
+ request.Content = replay;
+ }
+
+ LastRequest = request;
+ return await _responder(request, cancellationToken);
+ }
+ }
+}
diff --git a/apps/.net-sdk/Firecrawl/Firecrawl.csproj b/apps/.net-sdk/Firecrawl/Firecrawl.csproj
index 8672f896d..7919bc43e 100644
--- a/apps/.net-sdk/Firecrawl/Firecrawl.csproj
+++ b/apps/.net-sdk/Firecrawl/Firecrawl.csproj
@@ -8,7 +8,7 @@
<!-- NuGet package metadata -->
<PackageId>firecrawl-sdk</PackageId>
- <Version>1.0.0</Version>
+ <Version>1.1.0</Version>
<Authors>Firecrawl</Authors>
<Company>Firecrawl</Company>
<Description>.NET SDK for the Firecrawl API - web scraping, crawling, and data extraction</Description>
diff --git a/apps/.net-sdk/Firecrawl/FirecrawlClient.cs b/apps/.net-sdk/Firecrawl/FirecrawlClient.cs
index fb53d7dc7..1f2ae2b78 100644
--- a/apps/.net-sdk/Firecrawl/FirecrawlClient.cs
+++ b/apps/.net-sdk/Firecrawl/FirecrawlClient.cs
@@ -248,6 +248,56 @@ public class FirecrawlClient
$"/v2/batch/scrape/{jobId}", cancellationToken);
}
+ // ================================================================
+ // PARSE
+ // ================================================================
+
+ /// <summary>
+ /// Parses an uploaded file (HTML, PDF, DOCX, etc.) via <c>/v2/parse</c>
+ /// and returns the extracted document.
+ /// </summary>
+ /// <param name="file">The file to upload.</param>
+ /// <param name="options">Optional parse options. Browser-only formats
+ /// (changeTracking, screenshot, branding), actions, waitFor, location,
+ /// and mobile are rejected.</param>
+ /// <param name="cancellationToken">Cancellation token.</param>
+ public async Task<Document> ParseAsync(
+ ParseFile file,
+ ParseOptions? options = null,
+ CancellationToken cancellationToken = default)
+ {
+ ArgumentNullException.ThrowIfNull(file);
+
+ var filename = file.Filename?.Trim();
+ if (string.IsNullOrEmpty(filename))
+ throw new ArgumentException("filename cannot be empty", nameof(file));
+
+ if (file.Content is null || file.Content.Length == 0)
+ throw new ArgumentException("file content cannot be empty", nameof(file));
+
+ options?.Validate();
+
+ var optionsJson = JsonSerializer.Serialize(
+ options ?? new ParseOptions(),
+ FirecrawlHttpClient.JsonOptions);
+
+ var fields = new Dictionary<string, string>
+ {
+ ["options"] = optionsJson,
+ };
+
+ var response = await _http.PostMultipartAsync<ApiResponse<Document>>(
+ "/v2/parse",
+ fields,
+ fileField: "file",
+ fileName: filename,
+ fileContentType: file.ResolveContentType(),
+ fileContent: file.Content,
+ cancellationToken: cancellationToken);
+
+ return response.Data ?? throw new FirecrawlException("Parse response contained no data");
+ }
+
// ================================================================
// MAP
// ================================================================
diff --git a/apps/.net-sdk/Firecrawl/FirecrawlHttpClient.cs b/apps/.net-sdk/Firecrawl/FirecrawlHttpClient.cs
index e04b68d47..2da99b16e 100644
--- a/apps/.net-sdk/Firecrawl/FirecrawlHttpClient.cs
+++ b/apps/.net-sdk/Firecrawl/FirecrawlHttpClient.cs
@@ -57,31 +57,86 @@ internal class FirecrawlHttpClient
{
var url = _baseUrl + path;
var json = JsonSerializer.Serialize(body, JsonOptions);
- var content = new StringContent(json, Encoding.UTF8, "application/json");
- var request = new HttpRequestMessage(HttpMethod.Post, url) { Content = content };
- request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey);
- request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
+ HttpRequestMessage BuildRequest()
+ {
+ var content = new StringContent(json, Encoding.UTF8, "application/json");
+ var request = new HttpRequestMessage(HttpMethod.Post, url) { Content = content };
+ ApplyStandardHeaders(request);
+
+ if (extraHeaders != null)
+ {
+ foreach (var header in extraHeaders)
+ {
+ request.Headers.TryAddWithoutValidation(header.Key, header.Value);
+ }
+ }
+
+ return request;
+ }
- if (extraHeaders != null)
+ return await ExecuteWithRetryAsync<T>(BuildRequest, cancellationToken);
+ }
+
+ internal async Task<T> PostMultipartAsync<T>(
+ string path,
+ Dictionary<string, string> fields,
+ string fileField,
+ string fileName,
+ string fileContentType,
+ byte[] fileContent,
+ Dictionary<string, string>? extraHeaders = null,
+ CancellationToken cancellationToken = default)
+ {
+ var url = _baseUrl + path;
+
+ HttpRequestMessage BuildRequest()
{
- foreach (var header in extraHeaders)
+ var content = new MultipartFormDataContent();
+
+ foreach (var kv in fields)
{
- request.Headers.TryAddWithoutValidation(header.Key, header.Value);
+ var fieldContent = new StringContent(kv.Value, Encoding.UTF8);
+ fieldContent.Headers.ContentType = null;
+ content.Add(fieldContent, kv.Key);
}
+
+ var fileBytes = new ByteArrayContent(fileContent);
+ fileBytes.Headers.ContentType =
+ MediaTypeHeaderValue.Parse(string.IsNullOrWhiteSpace(fileContentType)
+ ? "application/octet-stream"
+ : fileContentType);
+ content.Add(fileBytes, fileField, fileName);
+
+ var request = new HttpRequestMessage(HttpMethod.Post, url) { Content = content };
+ ApplyStandardHeaders(request);
+
+ if (extraHeaders != null)
+ {
+ foreach (var header in extraHeaders)
+ {
+ request.Headers.TryAddWithoutValidation(header.Key, header.Value);
+ }
+ }
+
+ return request;
}
- return await ExecuteWithRetryAsync<T>(request, cancellationToken);
+ return await ExecuteWithRetryAsync<T>(BuildRequest, cancellationToken);
}
internal async Task<T> GetAsync<T>(string path, CancellationToken cancellationToken = default)
{
var url = _baseUrl + path;
- var request = new HttpRequestMessage(HttpMethod.Get, url);
- request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey);
- request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- return await ExecuteWithRetryAsync<T>(request, cancellationToken);
+ HttpRequestMessage BuildRequest()
+ {
+ var request = new HttpRequestMessage(HttpMethod.Get, url);
+ ApplyStandardHeaders(request);
+ return request;
+ }
+
+ return await ExecuteWithRetryAsync<T>(BuildRequest, cancellationToken);
}
internal async Task<T> GetAbsoluteAsync<T>(string absoluteUrl, CancellationToken cancellationToken = default)
@@ -98,33 +153,47 @@ internal class FirecrawlHttpClient
"Refusing to send credentials to a different origin.");
}
- var request = new HttpRequestMessage(HttpMethod.Get, absoluteUrl);
- request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey);
- request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
+ HttpRequestMessage BuildRequest()
+ {
+ var request = new HttpRequestMessage(HttpMethod.Get, absoluteUrl);
+ ApplyStandardHeaders(request);
+ return request;
+ }
- return await ExecuteWithRetryAsync<T>(request, cancellationToken);
+ return await ExecuteWithRetryAsync<T>(BuildRequest, cancellationToken);
}
internal async Task<T> DeleteAsync<T>(string path, CancellationToken cancellationToken = default)
{
var url = _baseUrl + path;
- var request = new HttpRequestMessage(HttpMethod.Delete, url);
+
+ HttpRequestMessage BuildRequest()
+ {
+ var request = new HttpRequestMessage(HttpMethod.Delete, url);
+ ApplyStandardHeaders(request);
+ return request;
+ }
+
+ return await ExecuteWithRetryAsync<T>(BuildRequest, cancellationToken);
+ }
+
+ private void ApplyStandardHeaders(HttpRequestMessage request)
+ {
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
-
- return await ExecuteWithRetryAsync<T>(request, cancellationToken);
}
private async Task<T> ExecuteWithRetryAsync<T>(
- HttpRequestMessage originalRequest,
+ Func<HttpRequestMessage> requestBuilder,
CancellationToken cancellationToken)
{
var attempt = 0;
while (true)
{
- // Clone the request for each attempt (HttpRequestMessage can only be sent once)
- using var request = await CloneRequestAsync(originalRequest);
+ // Build a fresh request for each attempt (HttpRequestMessage can only be sent once,
+ // and multipart content is not cheaply cloneable).
+ using var request = requestBuilder();
HttpResponseMessage? response = null;
try
@@ -186,24 +255,6 @@ internal class FirecrawlHttpClient
}
}
- private static async Task<HttpRequestMessage> CloneRequestAsync(HttpRequestMessage original)
- {
- var clone = new HttpRequestMessage(original.Method, original.RequestUri);
-
- if (original.Content != null)
- {
- var content = await original.Content.ReadAsStringAsync();
- clone.Content = new StringContent(content, Encoding.UTF8, "application/json");
- }
-
- foreach (var header in original.Headers)
- {
- clone.Headers.TryAddWithoutValidation(header.Key, header.Value);
- }
-
- return clone;
- }
-
private static string ExtractErrorMessage(string body, int statusCode)
{
try
diff --git a/apps/.net-sdk/Firecrawl/Models/ParseFile.cs b/apps/.net-sdk/Firecrawl/Models/ParseFile.cs
new file mode 100644
index 000000000..099d27d38
--- /dev/null
+++ b/apps/.net-sdk/Firecrawl/Models/ParseFile.cs
@@ -0,0 +1,80 @@
+namespace Firecrawl.Models;
+
+/// <summary>
+/// Uploaded file payload for the <c>/v2/parse</c> endpoint.
+/// </summary>
+public class ParseFile
+{
+ /// <summary>
+ /// Filename used in the multipart upload (e.g. <c>upload.pdf</c>).
+ /// </summary>
+ public string Filename { get; set; }
+
+ /// <summary>
+ /// Raw bytes of the file to be parsed.
+ /// </summary>
+ public byte[] Content { get; set; }
+
+ /// <summary>
+ /// Optional MIME type hint (e.g. <c>application/pdf</c>).
+ /// When null, the value is guessed from the filename extension,
+ /// falling back to <c>application/octet-stream</c>.
+ /// </summary>
+ public string? ContentType { get; set; }
+
+ public ParseFile(string filename, byte[] content, string? contentType = null)
+ {
+ Filename = filename;
+ Content = content;
+ ContentType = contentType;
+ }
+
+ /// <summary>
+ /// Build a <see cref="ParseFile"/> from raw bytes.
+ /// </summary>
+ public static ParseFile FromBytes(string filename, byte[] content, string? contentType = null)
+ => new(filename, content, contentType);
+
+ /// <summary>
+ /// Build a <see cref="ParseFile"/> by reading a file from disk.
+ /// The filename is derived from the path unless overridden.
+ /// </summary>
+ public static ParseFile FromPath(string path, string? filename = null, string? contentType = null)
+ {
+ if (string.IsNullOrWhiteSpace(path))
+ throw new ArgumentException("Path cannot be empty.", nameof(path));
+
+ if (!File.Exists(path))
+ throw new FileNotFoundException($"Parse file not found: {path}", path);
+
+ var bytes = File.ReadAllBytes(path);
+ var resolvedName = filename ?? Path.GetFileName(path);
+ return new ParseFile(resolvedName, bytes, contentType);
+ }
+
+ internal string ResolveContentType()
+ {
+ if (!string.IsNullOrWhiteSpace(ContentType))
+ return ContentType;
+
+ var extension = Path.GetExtension(Filename).ToLowerInvariant();
+ return extension switch
+ {
+ ".html" or ".htm" => "text/html",
+ ".pdf" => "application/pdf",
+ ".docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+ ".doc" => "application/msword",
+ ".xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ ".xls" => "application/vnd.ms-excel",
+ ".pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation",
+ ".ppt" => "application/vnd.ms-powerpoint",
+ ".txt" => "text/plain",
+ ".md" => "text/markdown",
+ ".csv" => "text/csv",
+ ".json" => "application/json",
+ ".xml" => "application/xml",
+ ".rtf" => "application/rtf",
+ _ => "application/octet-stream",
+ };
+ }
+}
diff --git a/apps/.net-sdk/Firecrawl/Models/ParseOptions.cs b/apps/.net-sdk/Firecrawl/Models/ParseOptions.cs
new file mode 100644
index 000000000..10ebc7587
--- /dev/null
+++ b/apps/.net-sdk/Firecrawl/Models/ParseOptions.cs
@@ -0,0 +1,134 @@
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace Firecrawl.Models;
+
+/// <summary>
+/// Options for the <c>/v2/parse</c> endpoint.
+///
+/// <para>
+/// Parse does not support browser-rendering formats/options such as change
+/// tracking, screenshot, branding, actions, waitFor, location, or mobile.
+/// These are rejected client-side in <see cref="Validate"/>.
+/// </para>
+/// </summary>
+public class ParseOptions
+{
+ internal static readonly HashSet<string> UnsupportedFormats = new(StringComparer.OrdinalIgnoreCase)
+ {
+ "changeTracking",
+ "change_tracking",
+ "screenshot",
+ "screenshot@fullPage",
+ "branding",
+ };
+
+ internal static readonly HashSet<string> SupportedProxies = new(StringComparer.OrdinalIgnoreCase)
+ {
+ "auto",
+ "basic",
+ };
+
+ [JsonPropertyName("formats")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public List<object>? Formats { get; set; }
+
+ [JsonPropertyName("headers")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public Dictionary<string, string>? Headers { get; set; }
+
+ [JsonPropertyName("includeTags")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public List<string>? IncludeTags { get; set; }
+
+ [JsonPropertyName("excludeTags")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public List<string>? ExcludeTags { get; set; }
+
+ [JsonPropertyName("onlyMainContent")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public bool? OnlyMainContent { get; set; }
+
+ [JsonPropertyName("timeout")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public int? Timeout { get; set; }
+
+ [JsonPropertyName("parsers")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public List<object>? Parsers { get; set; }
+
+ [JsonPropertyName("skipTlsVerification")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public bool? SkipTlsVerification { get; set; }
+
+ [JsonPropertyName("removeBase64Images")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public bool? RemoveBase64Images { get; set; }
+
+ [JsonPropertyName("blockAds")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public bool? BlockAds { get; set; }
+
+ [JsonPropertyName("proxy")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public string? Proxy { get; set; }
+
+ [JsonPropertyName("integration")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ public string? Integration { get; set; }
+
+ /// <summary>
+ /// Validate the options against /v2/parse's supported surface.
+ /// </summary>
+ /// <exception cref="ArgumentException">Thrown when an unsupported format,
+ /// proxy, or timeout value is set.</exception>
+ public void Validate()
+ {
+ if (Timeout is not null and <= 0)
+ throw new ArgumentException("timeout must be positive", nameof(Timeout));
+
+ if (!string.IsNullOrWhiteSpace(Proxy) && !SupportedProxies.Contains(Proxy))
+ throw new ArgumentException(
+ "parse only supports proxy values 'basic' or 'auto'", nameof(Proxy));
+
+ if (Formats is { Count: > 0 })
+ {
+ foreach (var fmt in Formats)
+ {
+ var type = ExtractFormatType(fmt);
+ if (type is not null && UnsupportedFormats.Contains(type))
+ throw new ArgumentException($"parse does not support format: {type}", nameof(Formats));
+ }
+ }
+ }
+
+ private static string? ExtractFormatType(object? format)
+ {
+ if (format is null)
+ return null;
+
+ if (format is string s)
+ return s;
+
+ if (format is IDictionary<string, object?> dict &&
+ dict.TryGetValue("type", out var typeObj) &&
+ typeObj is string ts)
+ {
+ return ts;
+ }
+
+ if (format is JsonElement element)
+ {
+ if (element.ValueKind == JsonValueKind.String)
+ return element.GetString();
+ if (element.ValueKind == JsonValueKind.Object &&
+ element.TryGetProperty("type", out var typeProp) &&
+ typeProp.ValueKind == JsonValueKind.String)
+ {
+ return typeProp.GetString();
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/apps/.net-sdk/README.md b/apps/.net-sdk/README.md
index 8de48be3c..70560fec1 100644
--- a/apps/.net-sdk/README.md
+++ b/apps/.net-sdk/README.md
@@ -128,6 +128,36 @@ foreach (var doc in job.Data!)
}
```
+### Parse
+
+Upload and parse a local file (HTML, PDF, DOCX, etc.) through the `/v2/parse`
+endpoint. Parse does not support browser-rendering options like `actions`,
+`waitFor`, `location`, `mobile`, or the `screenshot` / `branding` /
+`changeTracking` formats.
+
+```csharp
+using Firecrawl;
+using Firecrawl.Models;
+
+var client = new FirecrawlClient("fc-your-api-key");
+
+// From a file on disk
+var doc = await client.ParseAsync(
+ ParseFile.FromPath("report.pdf"),
+ new ParseOptions
+ {
+ Formats = new List<object> { "markdown" },
+ OnlyMainContent = true,
+ });
+
+Console.WriteLine(doc.Markdown);
+
+// From in-memory bytes
+byte[] html = File.ReadAllBytes("snapshot.html");
+var parsed = await client.ParseAsync(
+ ParseFile.FromBytes("snapshot.html", html, "text/html"));
+```
+
### Map (URL Discovery)
```csharp