Files
Karan LokchandaniandKris Oei 58d8c4bfab feat(sdks): add protein lookup to all SDKs (#5722)
* feat(sdks): add protein lookup to the Python and JS SDKs

* fix(sdks): restore the research_docs header, split the notice sentence, reuse RESEARCH_METHODS

The research_docs module docstring keeps main's wording and line breaks except for the added lookup_protein and five to six. The README notice line becomes two sentences. The sync and async client method checks now loop over RESEARCH_METHODS, so they cover lookup_protein.

* fix(sdks): keep the API's error message and code on research request failures

* feat(sdks): add protein lookup to the PHP, Ruby and Elixir SDKs

Add lookupProtein (PHP), lookup_protein (Ruby) and lookup_protein (Elixir), which call GET /v2/search/research/proteins with protein and an optional organism. The Elixir method sits in the hand-written region beside the paper methods, and generate.exs lists its route so a regenerate from the public spec emits no second definition.

* test(sdks): cover the protein lookup query in Ruby and PHP, document notice

Each test checks the path and that protein, origin and organism (only when set) reach the query string. The PHP, Ruby and Elixir doc comments now say the response's notice is the UniProt credit and license to show with the results.

* feat(sdks): add protein lookup to the Go, Rust, Java and .NET SDKs

* fix(sdks): rename GoTerm to ProteinGoTerm and cover origin and not_found

Rename the GO term type to ProteinGoTerm in the Go, Rust, Java and .NET
SDKs to match the other protein types and the JS SDK. Document that
notice carries UniProt's credit and CC BY 4.0 license. The protein tests
now assert that origin is sent, and the Rust test decodes a not_found
body.

---------

Co-authored-by: Kris Oei <oei.kris71@gmail.com>
2026-11-16 11:47:40 -08:00
..

Firecrawl Ruby SDK

Ruby SDK for Firecrawl, the context API for AI agents. Search, scrape, parse, crawl, map, and interact with the web, and run Agent and Monitor jobs on the v2 API.

Prerequisites

  • Ruby >= 3.0

Installation

Add to your Gemfile:

gem "firecrawl-sdk", "~> 1.5"

Or install directly:

gem install firecrawl-sdk

Quick Start

require "firecrawl"

# Create a client
client = Firecrawl::Client.new(api_key: "fc-your-api-key")

# Or load from FIRECRAWL_API_KEY environment variable
client = Firecrawl::Client.from_env

# Scrape a single page
doc = client.scrape("https://example.com")
puts doc.markdown

Environment Setup

export FIRECRAWL_API_KEY="fc-your-api-key"
# Optional: custom API URL
export FIRECRAWL_API_URL="http://localhost:3002"

API Reference

Scrape

# Basic scrape
doc = client.scrape("https://example.com")
puts doc.markdown

# Scrape with options
doc = client.scrape("https://example.com",
  Firecrawl::Models::ScrapeOptions.new(
    formats: ["markdown", "html"],
    only_main_content: true,
    wait_for: 1000
  ))
puts doc.html

Video Extraction

Use the video format on supported video URLs, including YouTube and TikTok. The returned video field is a signed URL to the extracted video file.

doc = client.scrape("https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  Firecrawl::Models::ScrapeOptions.new(formats: ["video"]))

puts doc.video

Product Extraction

Use the product format on product pages to get structured product data (title, brand, category, and per-variant price, availability, and images). It is the deterministic counterpart to the LLM-based json format. The returned product field contains the extracted fields.

doc = client.scrape("https://example.com/products/widget",
  Firecrawl::Models::ScrapeOptions.new(formats: ["product"]))

puts doc.product

Menu Extraction

Use the menu format on restaurant/merchant menu pages to get structured menu data (merchant profile plus ordered sections, each holding items with per-item price, availability, images, and dietary information). It is the deterministic counterpart to the LLM-based json format. The returned menu field contains the extracted fields.

doc = client.scrape("https://example.com/menu",
  Firecrawl::Models::ScrapeOptions.new(formats: ["menu"]))

puts doc.menu

Parse

Upload a local file (html, pdf, docx, etc.) via multipart form data and parse it synchronously. Parse options intentionally exclude browser-only features such as change tracking, screenshot, branding, audio, video, product, actions, wait_for, location, and mobile. The proxy option only accepts "auto" or "basic".

# From disk
file = Firecrawl::Models::ParseFile.from_path("./document.pdf")

# Or from memory
file = Firecrawl::Models::ParseFile.new(
  filename: "upload.html",
  content: "<html>hi</html>",
  content_type: "text/html"
)

doc = client.parse(file,
  Firecrawl::Models::ParseOptions.new(formats: ["markdown"]))
puts doc.markdown

List the file formats the parse endpoint accepts. available is false for formats the deployment can't currently handle (e.g. images when OCR is off).

client.get_parse_formats.each do |f|
  puts "#{f.format} (#{f.kind}) #{f.extensions.join(", ")} #{f.mime_types.join(", ")} available=#{f.available}"
end

Crawl

# Crawl with auto-polling (blocks until complete)
job = client.crawl("https://example.com",
  Firecrawl::Models::CrawlOptions.new(limit: 50))
job.data.each { |doc| puts doc.markdown }

# Async crawl
response = client.start_crawl("https://example.com",
  Firecrawl::Models::CrawlOptions.new(limit: 10))
puts response.id

# Check status
status = client.get_crawl_status(response.id)
puts status.status

# Cancel
client.cancel_crawl(response.id)

Batch Scrape

urls = ["https://example.com/page1", "https://example.com/page2"]

# Batch scrape with auto-polling
job = client.batch_scrape(urls,
  Firecrawl::Models::BatchScrapeOptions.new(
    options: Firecrawl::Models::ScrapeOptions.new(formats: ["markdown"])
  ))
job.data.each { |doc| puts doc.markdown }

Map

# Discover URLs on a website
result = client.map("https://example.com")
result.links.each { |link| puts link["url"] }

# With options
result = client.map("https://example.com",
  Firecrawl::Models::MapOptions.new(limit: 100, search: "blog"))
# Web search
results = client.search("firecrawl web scraping")
results.web&.each { |r| puts r["url"] }

# With options
results = client.search("latest news",
  Firecrawl::Models::SearchOptions.new(limit: 5, location: "US"))

Search public repositories, GitHub issues, merged pull requests, READMEs and code documentation. It replaces the research index GitHub search, which was removed after 2026-11-03.

response = client.developer_search(
  "retry an http request with exponential backoff",
  Firecrawl::Models::DeveloperSearchOptions.new(
    k: 5,
    types: ["issue", "pull_request"],
    repos: ["square/okhttp"]
  )
)

response.results.each do |result|
  puts "#{result.title} #{result.url}"
end

Agent

# Run an AI agent task (blocks until complete)
status = client.agent(
  Firecrawl::Models::AgentOptions.new(
    prompt: "Find the pricing information",
    urls: ["https://example.com"]
  ))
puts status.data

# Use Alexandria data providers connected in the dashboard
status = client.agent(
  Firecrawl::Models::AgentOptions.new(
    prompt: "Find the work email of the CEO of example.com",
    exchange: Firecrawl::Models::AgentExchangeOptions.new(
      enabled: true,
      toolkits: ["apollo"]
    )
  ))
puts status.exchange&.paid_calls

Usage & Metrics

# Check concurrency
concurrency = client.get_concurrency
puts concurrency.concurrency

# Check credit usage
usage = client.get_credit_usage
puts usage.remaining_credits

Configuration

client = Firecrawl::Client.new(
  api_key: "fc-your-api-key",
  api_url: "https://api.firecrawl.dev",  # custom API URL
  timeout: 300,                           # HTTP timeout in seconds
  max_retries: 3,                         # automatic retries
  backoff_factor: 0.5                     # exponential backoff factor
)

Error Handling

begin
  doc = client.scrape("https://example.com")
rescue Firecrawl::AuthenticationError => e
  puts "Invalid API key: #{e.message}"
rescue Firecrawl::RateLimitError => e
  puts "Rate limited: #{e.message}"
rescue Firecrawl::JobTimeoutError => e
  puts "Job #{e.job_id} timed out after #{e.timeout_seconds}s"
rescue Firecrawl::FirecrawlError => e
  puts "Error (#{e.status_code}): #{e.message}"
end

Development

Building from Source

cd apps/ruby-sdk
bundle install

Running Tests

# Unit tests
bundle exec rake test

# With API key for E2E tests
FIRECRAWL_API_KEY=fc-your-key bundle exec rake test

License

MIT License - see LICENSE.