Skip to content

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

feat(elixir-sdk): agent thread_id, mode and exchange (#4990)

Gergő Móricz1bf1215ca3b0
diff --git a/apps/elixir-sdk/generate.exs b/apps/elixir-sdk/generate.exs
index ca1a28e9a..17cba595b 100644
--- a/apps/elixir-sdk/generate.exs
+++ b/apps/elixir-sdk/generate.exs
@@ -252,15 +252,21 @@ defmodule Firecrawl.Generator do
defp to_body(validated_params, key_mapping) do
validated_params
- |> Map.new(fn {k, v} ->
- json_key = Map.fetch!(key_mapping, k)
- {json_key, to_json_value(v)}
- end)
+ |> to_json_object(key_mapping)
# Identify the SDK so the API can grant the keyless free tier; harmless
# telemetry on keyed requests.
|> Map.put_new("origin", @sdk_origin)
end
+ defp to_json_object(params, key_mapping) do
+ Map.new(params, fn {k, v} ->
+ case Map.fetch!(key_mapping, k) do
+ {json_key, nested_mapping} -> {json_key, to_json_object(v, nested_mapping)}
+ json_key -> {json_key, to_json_value(v)}
+ end
+ end)
+ end
+
defp to_query(validated_params, key_mapping) do
Enum.map(validated_params, fn {k, v} ->
{Map.fetch!(key_mapping, k), to_json_value(v)}
@@ -769,7 +775,7 @@ defmodule Firecrawl.Generator do
parts =
case Map.fetch(@type_overrides, {func_name, name}) do
{:ok, type} -> ["type: #{type}"]
- :error -> openapi_to_nimble_parts(name, prop_schema)
+ :error -> openapi_to_nimble_parts(prop_schema)
end
parts = if required, do: parts ++ ["required: true"], else: parts
@@ -783,15 +789,24 @@ defmodule Firecrawl.Generator do
end
defp generate_key_mapping(func_name, properties) do
+ " @#{func_name}_key_mapping #{key_mapping(properties)}\n"
+ end
+
+ # A closed object maps to {json_key, nested_mapping}, so to_body sends its exact
+ # wire names and an empty keyword list as {}.
+ defp key_mapping(properties) do
mappings =
properties
- |> Enum.map(fn {name, _} ->
- snake = to_snake_case(name)
- "#{snake}: #{inspect(name)}"
+ |> Enum.map(fn
+ {name, %{"type" => "object", "properties" => nested, "additionalProperties" => false}} ->
+ "#{to_snake_case(name)}: {#{inspect(name)}, #{key_mapping(nested)}}"
+
+ {name, _} ->
+ "#{to_snake_case(name)}: #{inspect(name)}"
end)
|> Enum.join(", ")
- " @#{func_name}_key_mapping %{#{mappings}}\n"
+ "%{#{mappings}}"
end
# ---------------------------------------------------------------------------
@@ -837,16 +852,17 @@ defmodule Firecrawl.Generator do
# OpenAPI → NimbleOptions type mapping
# ---------------------------------------------------------------------------
+ # A closed object (additionalProperties: false) validates its keys, so a typo
+ # fails locally instead of at the API.
defp openapi_to_nimble_parts(
- "auditMetadata",
- %{"type" => "object", "properties" => properties} = schema
+ %{"type" => "object", "properties" => properties, "additionalProperties" => false} = schema
) do
required = Map.get(schema, "required", [])
keys =
properties
|> Enum.map(fn {name, property_schema} ->
- parts = ["type: #{openapi_to_nimble_type(property_schema)}"]
+ parts = openapi_to_nimble_parts(property_schema)
parts = if name in required, do: parts ++ ["required: true"], else: parts
"#{to_snake_case(name)}: [#{Enum.join(parts, ", ")}]"
end)
@@ -855,7 +871,7 @@ defmodule Firecrawl.Generator do
["type: :keyword_list", "keys: [#{keys}]"]
end
- defp openapi_to_nimble_parts(_name, schema) do
+ defp openapi_to_nimble_parts(schema) do
["type: #{openapi_to_nimble_type(schema)}"]
end
diff --git a/apps/elixir-sdk/lib/firecrawl.ex b/apps/elixir-sdk/lib/firecrawl.ex
index bda8c1557..1cffa6cdb 100644
--- a/apps/elixir-sdk/lib/firecrawl.ex
+++ b/apps/elixir-sdk/lib/firecrawl.ex
@@ -89,15 +89,21 @@ defmodule Firecrawl do
defp to_body(validated_params, key_mapping) do
validated_params
- |> Map.new(fn {k, v} ->
- json_key = Map.fetch!(key_mapping, k)
- {json_key, to_json_value(v)}
- end)
+ |> to_json_object(key_mapping)
# Identify the SDK so the API can grant the keyless free tier; harmless
# telemetry on keyed requests.
|> Map.put_new("origin", @sdk_origin)
end
+ defp to_json_object(params, key_mapping) do
+ Map.new(params, fn {k, v} ->
+ case Map.fetch!(key_mapping, k) do
+ {json_key, nested_mapping} -> {json_key, to_json_object(v, nested_mapping)}
+ json_key -> {json_key, to_json_value(v)}
+ end
+ end)
+ end
+
defp to_query(validated_params, key_mapping) do
Enum.map(validated_params, fn {k, v} ->
{Map.fetch!(key_mapping, k), to_json_value(v)}
@@ -921,12 +927,13 @@ defmodule Firecrawl do
@create_browser_session_schema NimbleOptions.new!([
activity_ttl: [type: :integer, doc: "Time in seconds before the session is destroyed due to inactivity"],
+ block_ads: [type: :boolean, doc: "Enable ad and cookie popup blocking, as in scrape. Sessions started from a scrape with interact use the scrape's blockAds."],
profile: [type: :keyword_list, doc: "Enable persistent storage across interact sessions. Data saved in one session can be loaded in a later session using the same name."],
stream_web_view: [type: :boolean, doc: "Whether to stream a live view of the browser"],
ttl: [type: :integer, doc: "Total time-to-live in seconds for the interact session"]
])
- @create_browser_session_key_mapping %{activity_ttl: "activityTtl", profile: "profile", stream_web_view: "streamWebView", ttl: "ttl"}
+ @create_browser_session_key_mapping %{activity_ttl: "activityTtl", block_ads: "blockAds", profile: "profile", stream_web_view: "streamWebView", ttl: "ttl"}
@doc """
Create an interact session
@@ -1571,6 +1578,90 @@ defmodule Firecrawl do
end
+ @gov_search_query_schema NimbleOptions.new!([
+ query: [type: :string, required: true, doc: "Natural-language question or search phrase."],
+ k: [type: :integer, doc: "Number of results to return."]
+ ])
+
+ @gov_search_query_key_mapping %{query: "query", k: "k"}
+
+ @doc """
+ Search the Government Index
+
+ `GET /search/gov`
+
+ Tag: Government
+
+ ## Query Parameters
+
+ * `query` — query parameter `query`
+ * `k` — query parameter `k`
+
+ ## Returns
+
+ * `{:ok, %Req.Response{}}` on success
+ * `{:error, exception}` on HTTP or validation failure
+ """
+ @spec gov_search(keyword(), keyword()) :: response()
+ def gov_search(params \\ [], opts \\ []) do
+ with {:ok, params} <- NimbleOptions.validate(params, @gov_search_query_schema) do
+ Req.get(client(opts), url: "/search/gov", params: to_query(params, @gov_search_query_key_mapping))
+ end
+ end
+
+
+ @doc """
+ Bang variant of `gov_search`. Raises on error.
+ """
+ @spec gov_search!(keyword(), keyword()) :: Req.Response.t()
+ def gov_search!(params \\ [], opts \\ []) do
+ params = NimbleOptions.validate!(params, @gov_search_query_schema)
+ Req.get!(client(opts), url: "/search/gov", params: to_query(params, @gov_search_query_key_mapping))
+ end
+
+
+ @gov_search_post_schema NimbleOptions.new!([
+ k: [type: :integer, doc: "Number of results to return."],
+ query: [type: :string, required: true, doc: "Natural-language question or search phrase."]
+ ])
+
+ @gov_search_post_key_mapping %{k: "k", query: "query"}
+
+ @doc """
+ Search the Government Index
+
+ `POST /search/gov`
+
+ Tag: Government
+
+ ## Parameters
+
+ Validated by `NimbleOptions`. Pass params as a keyword list with snake_case keys.
+ See `@gov_search_post_schema` for the full schema.
+
+ ## Returns
+
+ * `{:ok, %Req.Response{}}` on success
+ * `{:error, exception}` on HTTP or validation failure
+ """
+ @spec gov_search_post(keyword(), keyword()) :: response()
+ def gov_search_post(params \\ [], opts \\ []) do
+ with {:ok, params} <- NimbleOptions.validate(params, @gov_search_post_schema) do
+ Req.post(client(opts), url: "/search/gov", json: to_body(params, @gov_search_post_key_mapping))
+ end
+ end
+
+
+ @doc """
+ Bang variant of `gov_search_post`. Raises on error.
+ """
+ @spec gov_search_post!(keyword(), keyword()) :: Req.Response.t()
+ def gov_search_post!(params \\ [], opts \\ []) do
+ params = NimbleOptions.validate!(params, @gov_search_post_schema)
+ Req.post!(client(opts), url: "/search/gov", json: to_body(params, @gov_search_post_key_mapping))
+ end
+
+
@interact_with_scrape_browser_session_schema NimbleOptions.new!([
code: [type: :string, required: true, doc: "Code to execute in the scrape-bound browser sandbox"],
language: [type: {:or, [{:in, [:python, :node, :bash]}, :string]}, doc: "Language of the code to execute. Use `node` for JavaScript or `bash` for agent-browser CLI commands."],
@@ -1713,7 +1804,7 @@ defmodule Firecrawl do
url: [type: :string, required: true, doc: "The base URL to start crawling from"]
])
- @map_urls_key_mapping %{audit_metadata: "auditMetadata", ignore_cache: "ignoreCache", ignore_query_parameters: "ignoreQueryParameters", include_subdomains: "includeSubdomains", limit: "limit", location: "location", search: "search", sitemap: "sitemap", threat_protection: "threatProtection", timeout: "timeout", url: "url"}
+ @map_urls_key_mapping %{audit_metadata: {"auditMetadata", %{username: "username"}}, ignore_cache: "ignoreCache", ignore_query_parameters: "ignoreQueryParameters", include_subdomains: "includeSubdomains", limit: "limit", location: "location", search: "search", sitemap: "sitemap", threat_protection: "threatProtection", timeout: "timeout", url: "url"}
@doc """
Map multiple URLs based on options
@@ -1769,7 +1860,7 @@ defmodule Firecrawl do
zero_data_retention: [type: :boolean, doc: "If true, this will enable zero data retention for this parse. To enable this feature, please contact [email protected]"]
])
- @parse_file_key_mapping %{audit_metadata: "auditMetadata", block_ads: "blockAds", exclude_tags: "excludeTags", formats: "formats", headers: "headers", include_tags: "includeTags", integration: "integration", only_main_content: "onlyMainContent", origin: "origin", parsers: "parsers", proxy: "proxy", redact_pii: "redactPII", remove_base64_images: "removeBase64Images", skip_tls_verification: "skipTlsVerification", timeout: "timeout", zero_data_retention: "zeroDataRetention"}
+ @parse_file_key_mapping %{audit_metadata: {"auditMetadata", %{username: "username"}}, block_ads: "blockAds", exclude_tags: "excludeTags", formats: "formats", headers: "headers", include_tags: "includeTags", integration: "integration", only_main_content: "onlyMainContent", origin: "origin", parsers: "parsers", proxy: "proxy", redact_pii: "redactPII", remove_base64_images: "removeBase64Images", skip_tls_verification: "skipTlsVerification", timeout: "timeout", zero_data_retention: "zeroDataRetention"}
@doc """
Upload and parse a file
@@ -1882,7 +1973,7 @@ defmodule Firecrawl do
domain_tools: [type: :boolean, doc: "When true on an ordinary URL scrape, `data.tools` lists tool contracts matched to the scraped page's domain (same `DiscoveredTool` shape as search). Requires the team's Alexandria access to be enabled and no zero data retention (403 otherwise). Free."]
])
- @scrape_and_extract_from_url_key_mapping %{url: "url", actions: "actions", audit_metadata: "auditMetadata", block_ads: "blockAds", exclude_tags: "excludeTags", formats: "formats", headers: "headers", include_tags: "includeTags", location: "location", lockdown: "lockdown", max_age: "maxAge", min_age: "minAge", mobile: "mobile", only_clean_content: "onlyCleanContent", only_main_content: "onlyMainContent", parsers: "parsers", profile: "profile", proxy: "proxy", redact_pii: "redactPII", remove_base64_images: "removeBase64Images", skip_tls_verification: "skipTlsVerification", store_in_cache: "storeInCache", threat_protection: "threatProtection", timeout: "timeout", wait_for: "waitFor", zero_data_retention: "zeroDataRetention", alexandria: "alexandria", domain_tools: "domainTools"}
+ @scrape_and_extract_from_url_key_mapping %{url: "url", actions: "actions", audit_metadata: {"auditMetadata", %{username: "username"}}, block_ads: "blockAds", exclude_tags: "excludeTags", formats: "formats", headers: "headers", include_tags: "includeTags", location: "location", lockdown: "lockdown", max_age: "maxAge", min_age: "minAge", mobile: "mobile", only_clean_content: "onlyCleanContent", only_main_content: "onlyMainContent", parsers: "parsers", profile: "profile", proxy: "proxy", redact_pii: "redactPII", remove_base64_images: "removeBase64Images", skip_tls_verification: "skipTlsVerification", store_in_cache: "storeInCache", threat_protection: "threatProtection", timeout: "timeout", wait_for: "waitFor", zero_data_retention: "zeroDataRetention", alexandria: "alexandria", domain_tools: "domainTools"}
@doc """
Scrape a single URL and optionally extract information using an LLM
@@ -1951,7 +2042,7 @@ defmodule Firecrawl do
zero_data_retention: [type: :boolean, doc: "If true, this will enable zero data retention for this batch scrape. To enable this feature, please contact [email protected]"]
])
- @scrape_and_extract_from_urls_key_mapping %{ignore_invalid_urls: "ignoreInvalidURLs", max_concurrency: "maxConcurrency", urls: "urls", webhook: "webhook", actions: "actions", audit_metadata: "auditMetadata", block_ads: "blockAds", exclude_tags: "excludeTags", formats: "formats", headers: "headers", include_tags: "includeTags", location: "location", lockdown: "lockdown", max_age: "maxAge", min_age: "minAge", mobile: "mobile", only_clean_content: "onlyCleanContent", only_main_content: "onlyMainContent", parsers: "parsers", profile: "profile", proxy: "proxy", redact_pii: "redactPII", remove_base64_images: "removeBase64Images", skip_tls_verification: "skipTlsVerification", store_in_cache: "storeInCache", threat_protection: "threatProtection", timeout: "timeout", wait_for: "waitFor", zero_data_retention: "zeroDataRetention"}
+ @scrape_and_extract_from_urls_key_mapping %{ignore_invalid_urls: "ignoreInvalidURLs", max_concurrency: "maxConcurrency", urls: "urls", webhook: "webhook", actions: "actions", audit_metadata: {"auditMetadata", %{username: "username"}}, block_ads: "blockAds", exclude_tags: "excludeTags", formats: "formats", headers: "headers", include_tags: "includeTags", location: "location", lockdown: "lockdown", max_age: "maxAge", min_age: "minAge", mobile: "mobile", only_clean_content: "onlyCleanContent", only_main_content: "onlyMainContent", parsers: "parsers", profile: "profile", proxy: "proxy", redact_pii: "redactPII", remove_base64_images: "removeBase64Images", skip_tls_verification: "skipTlsVerification", store_in_cache: "storeInCache", threat_protection: "threatProtection", timeout: "timeout", wait_for: "waitFor", zero_data_retention: "zeroDataRetention"}
@doc """
Scrape multiple URLs and optionally extract information using an LLM
@@ -2090,17 +2181,20 @@ defmodule Firecrawl do
@start_agent_schema NimbleOptions.new!([
audit_metadata: [type: :keyword_list, keys: [username: [type: :string, required: true]], doc: "User attribution included with SIEM logging events when SIEM Logging is enabled for the organization."],
effort: [type: {:in, ["low", "medium", "high"]}, doc: "Reasoning budget for the agent task. Every run executes on spark-2, so effort can be sent with or without model."],
+ exchange: [type: :keyword_list, keys: [approve: [type: :keyword_list, keys: [always: [type: :boolean], approval_id: [type: :string, required: true], call_ids: [type: {:list, :string}]]], decline: [type: :keyword_list, keys: [approval_id: [type: :string, required: true]]], enabled: [type: :boolean], max_calls: [type: :integer], on_terms_required: [type: {:or, [{:in, [:skip, :ask]}, :string]}], require_approval: [type: :boolean], toolkits: [type: {:list, :string}]], doc: "Let the agent call your team's [Alexandria](https://docs.firecrawl.dev/features/alexandria) data providers during the run. Without this object the run uses the web only (a follow-up turn inherits the previous turn's settings). See [Use your connected Alexandria tools](https://docs.firecrawl.dev/features/agent#use-your-connected-alexandria-tools)."],
max_credits: [type: {:or, [:integer, :float]}, doc: "Maximum credits to spend on this agent task. Defaults to 2500 if not set. Values above 2,500 are always billed as paid requests."],
+ mode: [type: {:or, [{:in, [:extract, :chat]}, :string]}, doc: "`extract` returns the complete structured result in `data` every turn. `chat` lets a follow-up that asks for no new data get a short reply in `message` instead of a re-run. `exchange.requireApproval` needs `chat` on the same request. Omitted on a follow-up turn keeps the thread's mode."],
model: [type: {:or, [{:in, [:"spark-2", :"spark-1-mini", :"spark-1-pro"]}, :string]}, doc: "The model to use for the agent task. spark-2 is the default and the model every run executes on. The Spark 1 model names remain accepted for backwards compatibility but are deprecated and route to spark-2."],
prompt: [type: :string, required: true, doc: "The prompt describing what data to extract"],
schema: [type: :any, doc: "Optional JSON schema to structure the extracted data"],
strict_constrain_to_urls: [type: :boolean, doc: "If true, agent will only visit URLs provided in the urls array"],
+ thread_id: [type: :string, doc: "Continue an existing thread: pass the `threadId` an earlier run returned, and this request runs as that thread's next turn. Omitted `urls`, `schema`, `effort`, `mode` and `exchange` settings carry over from the previous turn. Omit `threadId` to start a new thread."],
threat_protection: [type: :keyword_list, doc: "Per-request [Threat Protection](https://docs.firecrawl.dev/features/threat-protection) override. Fields you provide replace the corresponding fields of your organization's policy for this request only; omitted fields keep their organization-level values. Requires Threat Protection to be enabled for your team (enterprise feature) — otherwise the request is rejected with a 403. If your organization has disabled request overrides, any request that includes this object is rejected with a 403. If Threat Protection is enforced for your team, `mode` may not be set to `off`."],
urls: [type: {:list, :string}, doc: "Optional list of URLs to constrain the agent to"],
webhook: [type: :keyword_list, doc: "A webhook specification object. Subscribes to agent lifecycle events (agent.started, agent.action, agent.completed, agent.failed, agent.cancelled)."]
])
- @start_agent_key_mapping %{audit_metadata: "auditMetadata", effort: "effort", max_credits: "maxCredits", model: "model", prompt: "prompt", schema: "schema", strict_constrain_to_urls: "strictConstrainToURLs", threat_protection: "threatProtection", urls: "urls", webhook: "webhook"}
+ @start_agent_key_mapping %{audit_metadata: {"auditMetadata", %{username: "username"}}, effort: "effort", exchange: {"exchange", %{approve: {"approve", %{always: "always", approval_id: "approvalId", call_ids: "callIds"}}, decline: {"decline", %{approval_id: "approvalId"}}, enabled: "enabled", max_calls: "maxCalls", on_terms_required: "onTermsRequired", require_approval: "requireApproval", toolkits: "toolkits"}}, max_credits: "maxCredits", mode: "mode", model: "model", prompt: "prompt", schema: "schema", strict_constrain_to_urls: "strictConstrainToURLs", thread_id: "threadId", threat_protection: "threatProtection", urls: "urls", webhook: "webhook"}
@doc """
Start an agent task for agentic data extraction
diff --git a/apps/elixir-sdk/mix.exs b/apps/elixir-sdk/mix.exs
index 012caba31..fdb9202df 100644
--- a/apps/elixir-sdk/mix.exs
+++ b/apps/elixir-sdk/mix.exs
@@ -1,7 +1,7 @@
defmodule Firecrawl.MixProject do
use Mix.Project
- @version "1.11.3"
+ @version "1.12.0"
@source_url "https://github.com/firecrawl/firecrawl/tree/main/apps/elixir-sdk"
def project do
diff --git a/apps/elixir-sdk/openapi.json b/apps/elixir-sdk/openapi.json
index 523e354e9..f25d89060 100644
--- a/apps/elixir-sdk/openapi.json
+++ b/apps/elixir-sdk/openapi.json
@@ -3077,6 +3077,103 @@
},
"threatProtection": {
"$ref": "#/components/schemas/ThreatProtectionOverride"
+ },
+ "threadId": {
+ "type": "string",
+ "format": "uuid",
+ "description": "Continue an existing thread: pass the `threadId` an earlier run returned, and this request runs as that thread's next turn. Omitted `urls`, `schema`, `effort`, `mode` and `exchange` settings carry over from the previous turn. Omit `threadId` to start a new thread."
+ },
+ "mode": {
+ "type": "string",
+ "enum": [
+ "extract",
+ "chat"
+ ],
+ "default": "extract",
+ "description": "`extract` returns the complete structured result in `data` every turn. `chat` lets a follow-up that asks for no new data get a short reply in `message` instead of a re-run. `exchange.requireApproval` needs `chat` on the same request. Omitted on a follow-up turn keeps the thread's mode."
+ },
+ "exchange": {
+ "type": "object",
+ "description": "Let the agent call your team's [Alexandria](https://docs.firecrawl.dev/features/alexandria) data providers during the run. Without this object the run uses the web only (a follow-up turn inherits the previous turn's settings). See [Use your connected Alexandria tools](https://docs.firecrawl.dev/features/agent#use-your-connected-alexandria-tools).",
+ "additionalProperties": false,
+ "properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true,
+ "description": "Let the agent call Alexandria providers. Defaults to `true` once `exchange` is sent; send `false` to turn providers off for a turn of a thread."
+ },
+ "toolkits": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "maxItems": 5,
+ "description": "Pin up to 5 providers by slug, for example `[\"apollo\"]`. The agent then uses only those. Empty or omitted means every provider your team can use."
+ },
+ "maxCalls": {
+ "type": "integer",
+ "minimum": 1,
+ "maximum": 30,
+ "default": 16,
+ "description": "Most provider calls the agent may make in this turn."
+ },
+ "requireApproval": {
+ "type": "boolean",
+ "default": false,
+ "description": "Before any paid provider call, end the turn with a `pendingApproval` of kind `calls` that you approve or decline on the next turn. Requires `mode: \"chat\"` on the same request, including on a follow-up."
+ },
+ "approve": {
+ "type": "object",
+ "description": "Answer yes to the `pendingApproval` the previous turn of this thread ended on. Needs `threadId`.",
+ "additionalProperties": false,
+ "properties": {
+ "approvalId": {
+ "type": "string",
+ "format": "uuid",
+ "description": "The `pendingApproval.id` to answer."
+ },
+ "callIds": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "description": "Run only these calls from the approval. Defaults to all of them. Ignored on a `terms` approval."
+ },
+ "always": {
+ "type": "boolean",
+ "default": false,
+ "description": "Stop asking for approval for the rest of the thread. Ignored on a `terms` approval."
+ }
+ },
+ "required": [
+ "approvalId"
+ ]
+ },
+ "decline": {
+ "type": "object",
+ "description": "Answer no to the `pendingApproval` the previous turn of this thread ended on. Needs `threadId`. A declined `terms` offer keeps its providers out of the rest of the thread.",
+ "additionalProperties": false,
+ "properties": {
+ "approvalId": {
+ "type": "string",
+ "format": "uuid",
+ "description": "The `pendingApproval.id` to answer."
+ }
+ },
+ "required": [
+ "approvalId"
+ ]
+ },
+ "onTermsRequired": {
+ "type": "string",
+ "enum": [
+ "skip",
+ "ask"
+ ],
+ "default": "skip",
+ "description": "What to do when a provider the agent would use needs data terms your team has not accepted. Such providers are never called. `skip` answers with accepted providers and lists the others in `exchange.skippedProviders`; `ask` also ends the turn with a `terms` `pendingApproval` and `exchange.requiresAction`. Omitted on a follow-up turn keeps the previous turn's value. See [Data providers that need terms](https://docs.firecrawl.dev/features/agent#data-providers-that-need-terms)."
+ }
+ }
}
},
"required": [
@@ -3100,6 +3197,15 @@
"id": {
"type": "string",
"format": "uuid"
+ },
+ "threadId": {
+ "type": "string",
+ "format": "uuid",
+ "description": "The thread this run belongs to. Pass it as `threadId` to continue the thread."
+ },
+ "threadTurn": {
+ "type": "integer",
+ "description": "This run's turn in the thread, starting at 1."
}
}
}
@@ -3234,7 +3340,25 @@
},
"data": {
"type": "object",
- "description": "The extracted data (only present when status is completed)"
+ "description": "The extracted data (only present when status is completed). Never set on a failed run, including one that stopped at its credit limit."
+ },
+ "partial": {
+ "description": "Best-effort JSON recovered from an incomplete run. Only present on some failed runs, such as one that reached `maxCredits`; never present while the run is processing. It may be missing rows or fields, so do not treat it as a completed result."
+ },
+ "partialSchemaValid": {
+ "type": "boolean",
+ "description": "Whether `partial` validates against the request's JSON schema. Only present when `partial` is present and the request included a `schema`."
+ },
+ "stopReason": {
+ "type": "string",
+ "enum": [
+ "credit_limit_reached"
+ ],
+ "description": "Why a failed run stopped early. `credit_limit_reached` means the run hit its `maxCredits` limit. Only present when status is failed."
+ },
+ "message": {
+ "type": "string",
+ "description": "A note from the agent about the result. In `chat` mode, a follow-up that asks for no new data is answered here instead of in `data`. On a failed credit-limit stop, it may explain what is incomplete."
},
"model": {
"type": "string",
@@ -3265,6 +3389,43 @@
},
"creditsUsed": {
"type": "number"
+ },
+ "threadId": {
+ "type": "string",
+ "format": "uuid",
+ "description": "The thread this run belongs to."
+ },
+ "threadTurn": {
+ "type": "integer",
+ "description": "This run's turn in the thread, starting at 1."
+ },
+ "mode": {
+ "type": "string",
+ "enum": [
+ "extract",
+ "chat"
+ ]
+ },
+ "suggestions": {
+ "type": "array",
+ "description": "Follow-ups the agent offers for the next turn of the thread.",
+ "items": {
+ "type": "object",
+ "properties": {
+ "label": {
+ "type": "string"
+ },
+ "prompt": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ "pendingApproval": {
+ "$ref": "#/components/schemas/AgentPendingApproval"
+ },
+ "exchange": {
+ "$ref": "#/components/schemas/AgentExchangeSummary"
}
}
}
@@ -4464,6 +4625,21 @@
"type"
]
},
+ {
+ "type": "object",
+ "title": "Gov",
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": [
+ "gov"
+ ]
+ }
+ },
+ "required": [
+ "type"
+ ]
+ },
{
"type": "object",
"title": "Research",
@@ -4929,6 +5105,11 @@
"default": true,
"description": "Whether to stream a live view of the browser"
},
+ "blockAds": {
+ "type": "boolean",
+ "default": true,
+ "description": "Enable ad and cookie popup blocking, as in scrape. Sessions started from a scrape with interact use the scrape's blockAds."
+ },
"profile": {
"type": "object",
"description": "Enable persistent storage across interact sessions. Data saved in one session can be loaded in a later session using the same name.",
@@ -6379,6 +6560,155 @@
}
}
},
+ "/search/gov": {
+ "get": {
+ "summary": "Search the Government Index",
+ "operationId": "govSearch",
+ "tags": [
+ "Government"
+ ],
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "parameters": [
+ {
+ "name": "query",
+ "in": "query",
+ "required": true,
+ "description": "Natural-language question or search phrase.",
+ "schema": {
+ "type": "string",
+ "minLength": 1
+ }
+ },
+ {
+ "name": "k",
+ "in": "query",
+ "required": false,
+ "description": "Number of results to return.",
+ "schema": {
+ "type": "integer",
+ "minimum": 1,
+ "maximum": 100,
+ "default": 10
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Ranked Government Index results in the `web` group.",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/GovSearchResponse"
+ },
+ "example": {
+ "success": true,
+ "data": {
+ "web": [
+ {
+ "url": "https://www.ecfr.gov/current/title-21/chapter-I/subchapter-B/part-101",
+ "title": "21 CFR Part 101 -- Food Labeling",
+ "description": "Nutrition labeling of food shall be provided for all products intended for human consumption...",
+ "position": 1
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "Invalid request, including an unknown field"
+ },
+ "401": {
+ "description": "Invalid bearer token"
+ },
+ "429": {
+ "description": "Rate limit exceeded"
+ },
+ "502": {
+ "description": "Upstream error"
+ },
+ "504": {
+ "description": "Upstream timeout"
+ }
+ }
+ },
+ "post": {
+ "summary": "Search the Government Index",
+ "operationId": "govSearchPost",
+ "tags": [
+ "Government"
+ ],
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "requestBody": {
+ "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "required": [
+ "query"
+ ],
+ "additionalProperties": false,
+ "properties": {
+ "query": {
+ "type": "string",
+ "minLength": 1,
+ "description": "Natural-language question or search phrase."
+ },
+ "k": {
+ "type": "integer",
+ "minimum": 1,
+ "maximum": 100,
+ "default": 10,
+ "description": "Number of results to return."
+ }
+ }
+ },
+ "example": {
+ "query": "food labeling requirements for allergens",
+ "k": 10
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "Ranked Government Index results in the `web` group.",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/GovSearchResponse"
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "Invalid request, including an unknown field"
+ },
+ "401": {
+ "description": "Invalid bearer token"
+ },
+ "429": {
+ "description": "Rate limit exceeded"
+ },
+ "502": {
+ "description": "Upstream error"
+ },
+ "504": {
+ "description": "Upstream timeout"
+ }
+ }
+ }
+ },
"/feedback": {
"post": {
"summary": "Submit feedback for a v2 job",
@@ -12383,6 +12713,42 @@
}
}
},
+ "GovSearchResponse": {
+ "type": "object",
+ "properties": {
+ "success": {
+ "type": "boolean"
+ },
+ "data": {
+ "type": "object",
+ "properties": {
+ "web": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "url": {
+ "type": "string",
+ "format": "uri"
+ },
+ "title": {
+ "type": "string"
+ },
+ "description": {
+ "type": "string",
+ "description": "Matched snippet from the source document."
+ },
+ "position": {
+ "type": "integer",
+ "description": "1-based rank in the result list."
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"EndpointFeedbackRequest": {
"allOf": [
{
@@ -12587,6 +12953,246 @@
"description": "What to do when the classifier can't be reached: `closed` blocks the request, `open` allows it."
}
}
+ },
+ "AgentPendingApproval": {
+ "type": "object",
+ "description": "What the turn stopped to ask. Answer it on the next turn of the thread with `exchange.approve` or `exchange.decline`.",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "Send this as `approvalId`."
+ },
+ "kind": {
+ "type": "string",
+ "enum": [
+ "calls",
+ "terms"
+ ],
+ "description": "`calls`: paid provider calls held back by `requireApproval`. `terms`: providers whose data terms need accepting (`onTermsRequired: \"ask\"`). Absent on items written before terms offers existed, which are `calls`."
+ },
+ "reason": {
+ "type": "string",
+ "description": "Why the agent wants to make these calls."
+ },
+ "calls": {
+ "type": "array",
+ "description": "The paid calls waiting for approval. Empty on a `terms` approval.",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "description": "Pass in `exchange.approve.callIds` to approve only some calls."
+ },
+ "provider": {
+ "type": "string"
+ },
+ "capability": {
+ "type": "string"
+ },
+ "input": {
+ "type": "object",
+ "description": "The options the call would run with."
+ },
+ "more": {
+ "type": "array",
+ "items": {
+ "type": "object"
+ },
+ "description": "Further inputs the same call would run with."
+ },
+ "creditsEstimate": {
+ "type": "number",
+ "nullable": true,
+ "description": "Estimated credits, or null when unknown."
+ }
+ }
+ }
+ },
+ "terms": {
+ "type": "array",
+ "description": "On a `terms` approval, the providers whose terms need accepting.",
+ "items": {
+ "type": "object",
+ "properties": {
+ "provider": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "capability": {
+ "type": "string"
+ },
+ "adds": {
+ "type": "string",
+ "description": "What the provider would add."
+ },
+ "version": {
+ "type": "string",
+ "description": "The terms version."
+ },
+ "digest": {
+ "type": "string",
+ "nullable": true,
+ "description": "Null when the catalog published no digest; `terms/show` returns it."
+ },
+ "url": {
+ "type": "string",
+ "description": "Where a person accepts the terms in the dashboard."
+ }
+ }
+ }
+ },
+ "resolution": {
+ "type": "object",
+ "nullable": true,
+ "description": "Null until a later turn answers the approval.",
+ "properties": {
+ "approved": {
+ "type": "boolean"
+ },
+ "callIds": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "always": {
+ "type": "boolean"
+ },
+ "byRunId": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ },
+ "AgentExchangeSummary": {
+ "type": "object",
+ "description": "What the run did with Alexandria. `toolkits` and `requireApproval` are what the run resolved to after thread inheritance.",
+ "properties": {
+ "enabled": {
+ "type": "boolean"
+ },
+ "toolkits": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "description": "Pinned providers. Empty or absent means every provider the team can use."
+ },
+ "requireApproval": {
+ "type": "boolean"
+ },
+ "onTermsRequired": {
+ "type": "string",
+ "enum": [
+ "skip",
+ "ask"
+ ]
+ },
+ "paidCalls": {
+ "type": "integer",
+ "description": "Paid provider calls the run made."
+ },
+ "creditsUsed": {
+ "type": "number",
+ "nullable": true,
+ "description": "Credits the provider calls used, or null when unknown."
+ },
+ "skippedProviders": {
+ "type": "array",
+ "description": "Providers that would have helped but need data terms your team has not accepted. Any `onTermsRequired` mode.",
+ "items": {
+ "type": "object",
+ "properties": {
+ "provider": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "capability": {
+ "type": "string"
+ },
+ "adds": {
+ "type": "string",
+ "description": "What the provider would have added."
+ },
+ "reason": {
+ "type": "string",
+ "enum": [
+ "terms_required"
+ ]
+ },
+ "version": {
+ "type": "string",
+ "description": "The terms version."
+ },
+ "termsUrl": {
+ "type": "string",
+ "description": "Where a person accepts the terms in the dashboard."
+ }
+ }
+ }
+ },
+ "requiresAction": {
+ "type": "object",
+ "description": "`onTermsRequired: \"ask\"` only, when a terms offer ended the turn: the calls to view and accept each provider's terms. Nothing here runs for you, and `terms/accept` must only be called after your user explicitly agrees.",
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": [
+ "accept_terms"
+ ]
+ },
+ "approvalId": {
+ "type": "string",
+ "description": "The `terms` `pendingApproval` to answer once the terms are accepted."
+ },
+ "providers": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "provider": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ },
+ "capability": {
+ "type": "string"
+ },
+ "adds": {
+ "type": "string"
+ },
+ "version": {
+ "type": "string"
+ },
+ "digest": {
+ "type": "string",
+ "nullable": true,
+ "description": "Null when the catalog published no digest; `terms/show` returns it."
+ },
+ "url": {
+ "type": "string"
+ },
+ "show": {
+ "type": "object",
+ "description": "The `terms/show` call, as `{ provider, capability, options }` for `/v2/scrape` `alexandria`."
+ },
+ "accept": {
+ "type": "object",
+ "description": "The `terms/accept` call, as `{ provider, capability, options }` for `/v2/scrape` `alexandria`."
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
}
},
diff --git a/apps/elixir-sdk/test/firecrawl_test.exs b/apps/elixir-sdk/test/firecrawl_test.exs
index da6fb09f2..7b09f66d5 100644
--- a/apps/elixir-sdk/test/firecrawl_test.exs
+++ b/apps/elixir-sdk/test/firecrawl_test.exs
@@ -192,6 +192,107 @@ defmodule FirecrawlTest do
Firecrawl.start_agent(prompt: "test", effort: "ultra")
end
+ # Sends the request body as decoded from the bytes put on the wire.
+ defp wire_body_adapter(parent) do
+ fn request ->
+ send(parent, {:body, request.body |> IO.iodata_to_binary() |> Jason.decode!()})
+ {request, Req.Response.new(status: 200, body: "")}
+ end
+ end
+
+ test "start_agent and start_agent! send thread_id, mode and exchange with camelCase keys at every level" do
+ opts = [api_key: "test-key", adapter: wire_body_adapter(self())]
+ thread_id = "6f1c2a4e-0d8b-4c1e-9a57-3b2f8e9d1c40"
+ origin = "elixir-sdk@" <> Mix.Project.config()[:version]
+
+ assert {:ok, %Req.Response{status: 200}} =
+ Firecrawl.start_agent(
+ [
+ prompt: "find leads",
+ thread_id: thread_id,
+ mode: :chat,
+ exchange: [
+ enabled: true,
+ toolkits: ["apollo"],
+ max_calls: 5,
+ require_approval: true,
+ approve: [approval_id: "approval-1", call_ids: ["c1"], always: true],
+ on_terms_required: :ask
+ ]
+ ],
+ opts
+ )
+
+ assert_receive {:body, body}
+
+ assert body == %{
+ "prompt" => "find leads",
+ "threadId" => thread_id,
+ "mode" => "chat",
+ "exchange" => %{
+ "enabled" => true,
+ "toolkits" => ["apollo"],
+ "maxCalls" => 5,
+ "requireApproval" => true,
+ "approve" => %{"approvalId" => "approval-1", "callIds" => ["c1"], "always" => true},
+ "onTermsRequired" => "ask"
+ },
+ "origin" => origin
+ }
+
+ assert %Req.Response{status: 200} =
+ Firecrawl.start_agent!(
+ [
+ prompt: "skip that",
+ thread_id: thread_id,
+ exchange: [decline: [approval_id: "approval-2"]]
+ ],
+ opts
+ )
+
+ assert_receive {:body, body}
+
+ assert body == %{
+ "prompt" => "skip that",
+ "threadId" => thread_id,
+ "exchange" => %{"decline" => %{"approvalId" => "approval-2"}},
+ "origin" => origin
+ }
+ end
+
+ test "start_agent leaves omitted thread, mode and exchange fields out of the body" do
+ opts = [api_key: "test-key", adapter: wire_body_adapter(self())]
+ origin = "elixir-sdk@" <> Mix.Project.config()[:version]
+
+ assert {:ok, _} = Firecrawl.start_agent([prompt: "find pricing"], opts)
+ assert_receive {:body, body}
+ assert body == %{"prompt" => "find pricing", "origin" => origin}
+
+ assert {:ok, _} = Firecrawl.start_agent([prompt: "find pricing", exchange: [toolkits: ["apollo"]]], opts)
+ assert_receive {:body, body}
+ assert body == %{"prompt" => "find pricing", "exchange" => %{"toolkits" => ["apollo"]}, "origin" => origin}
+
+ assert {:ok, _} = Firecrawl.start_agent([prompt: "find pricing", exchange: []], opts)
+ assert_receive {:body, body}
+ assert body == %{"prompt" => "find pricing", "exchange" => %{}, "origin" => origin}
+ end
+
+ test "start_agent rejects unknown or incomplete exchange keys before sending" do
+ opts = [api_key: "test-key", adapter: wire_body_adapter(self())]
+
+ assert {:error, %NimbleOptions.ValidationError{message: msg}} =
+ Firecrawl.start_agent([prompt: "find leads", exchange: [max_call: 5]], opts)
+
+ assert msg =~ "unknown options [:max_call]"
+
+ assert {:error, %NimbleOptions.ValidationError{message: msg}} =
+ Firecrawl.start_agent([prompt: "find leads", exchange: [approve: [call_ids: ["c1"]]]], opts)
+
+ assert msg =~ "required :approval_id option not found"
+
+ refute_received {:body, _}
+ end
+
test "get_agent_trace hits /v2/agent/:id/trace" do
parent = self()