Skip to content

benjaminjackson/exa-ruby

Repository files navigation

exa-ruby

Ruby client for the Exa.ai API. Search and analyze web content using neural search, question answering, code discovery, and research automation.

Installation

Add to your Gemfile:

gem 'exa-ai'

Then run:

bundle install

Or install directly:

gem install exa-ai

Configuration

Get your API key from dashboard.exa.ai.

Environment Variable (recommended)

export EXA_API_KEY="your-api-key-here"

Ruby Code

require 'exa-ai'

Exa.configure do |config|
  config.api_key = "your-api-key-here"
end

# Or pass directly to client
client = Exa::Client.new(api_key: "your-api-key-here")

CLI Flag

exa-ai search "query" --api-key YOUR_API_KEY

Quick Start

Ruby API

require 'exa-ai'

Exa.configure do |config|
  config.api_key = ENV['EXA_API_KEY']
end

client = Exa::Client.new

# Search the web
results = client.search("ruby programming")
results.results.each { |item| puts "#{item['title']}: #{item['url']}" }

# Get an answer to a question
answer = client.answer("What are the latest trends in AI?")
puts answer.answer

# Find code examples
code = client.context("React hooks")
puts code.response

# Get page contents
contents = client.get_contents(["https://example.com"])
puts contents.results.first["text"]

Command Line

# Search the web
exa-ai search "ruby programming"

# Answer a question
exa-ai answer "What is machine learning?"

# Find code examples
exa-ai context "async/await error handling"

# Get page contents
exa-ai get-contents "https://example.com"

# Start a research task
exa-ai research-start --instructions "Analyze recent ML papers" --wait

Features

The gem provides complete access to Exa's API endpoints:

  • Search — Neural and keyword search across billions of web pages
  • Answer — Generate comprehensive answers with source citations
  • Context — Find relevant code and documentation snippets
  • Get Contents — Extract full text content from web pages
  • Research — Start and manage long-running research tasks with AI

Error Handling

require 'exa-ai'

client = Exa::Client.new(api_key: "your-key")

begin
  results = client.search("test")
rescue Exa::Unauthorized => e
  puts "Invalid API key: #{e.message}"
rescue Exa::TooManyRequests => e
  puts "Rate limited, please retry"
rescue Exa::ServerError => e
  puts "Server error: #{e.message}"
end

Documentation

Development

See CONTRIBUTING.md for:

  • Running tests
  • Development setup
  • Code conventions
  • Building and releasing

Support

License

MIT License - See LICENSE file for details


Built with Exa.ai — The search and discovery API

About

Ruby client for Exa.ai API.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages