You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The contents endpoint retrieves full page content, summaries, and highlights for a list of URLs. Results are returned from cache when available, with live crawling as a fallback.
Basic Usage
request=Exa::ContentsRequest.new(api_key: ENV['EXA_API_KEY'])urls=['https://example.com/page1','https://example.com/page2']response=request.submit(urls)ifresponse.success?response.result.eachdo | result |
putsresult.titleputsresult.textendend
Options
Options can be passed as a hash or built using the DSL:
# using DSLoptions=Exa::ContentsOptions.builddotext{max_characters2000}highlights{num_sentences3}end# using hashoptions={text: {max_characters: 2000},highlights: {num_sentences: 3}}response=request.submit(urls,options)
Exa.api_keyENV['EXA_API_KEY']urls=['https://ruby-doc.org/core/Array.html','https://ruby-doc.org/core/Hash.html']response=Exa.contents(urls)ifresponse.success?response.result.eachdo | result |
putsresult.titleputsresult.text[0,500]putsendend
Content with Highlights
options=Exa::ContentsOptions.builddohighlightsdonum_sentences2highlights_per_url3query'Key methods and usage examples'endendresponse=Exa.contents(urls,options)ifresponse.success?response.result.eachdo | result |
puts"=" * 60putsresult.titleputs"-" * 60result.highlights&.eachdo | highlight |
puts"- #{highlight}"endputsendend
Content with Summaries
options=Exa::ContentsOptions.builddosummarydoquery'Summarize the main functionality and common use cases'endendresponse=Exa.contents(urls,options)ifresponse.success?response.result.eachdo | result |
putsresult.titleputsresult.summaryputsendend
A common pattern is to search first, then retrieve full content for specific results:
# First, search for relevant pagessearch_response=Exa.search('Ruby concurrency patterns',{num_results: 5})ifsearch_response.success?# Extract URLs from search resultsurls=search_response.result.map( &:url)# Fetch full content for those URLscontents_options=Exa::ContentsOptions.builddotext{max_characters5000}summary{query'Summarize the concurrency approach'}endcontents_response=Exa.contents(urls,contents_options)ifcontents_response.success?contents_response.result.eachdo | result |
putsresult.titleputsresult.summaryputsendendend