Once you’ve installed the SDKs, create a file called exa.py and add the code below.
Get a list of results and their full text content.
python
Copy
Ask AI
from exa_py import Exafrom dotenv import load_dotenvimport os# Use .env to store your API key or paste it directly into the codeload_dotenv()exa = Exa(os.getenv('EXA_API_KEY'))result = exa.search_and_contents( "An article about the state of AGI", type="auto", text=True,)print(result)
Get a list of results and their full text content.
python
Copy
Ask AI
from exa_py import Exafrom dotenv import load_dotenvimport os# Use .env to store your API key or paste it directly into the codeload_dotenv()exa = Exa(os.getenv('EXA_API_KEY'))result = exa.search_and_contents( "An article about the state of AGI", type="auto", text=True,)print(result)
Get an answer to a question, grounded by citations from exa.
python
Copy
Ask AI
from exa_py import Exafrom dotenv import load_dotenvimport os# Use .env to store your API key or paste it directly into the codeload_dotenv()exa = Exa(os.getenv('EXA_API_KEY'))result = exa.stream_answer( "What are the latest findings on gut microbiome's influence on mental health?", text=True,)for chunk in result: print(chunk, end='', flush=True)
Get a chat completion from exa.
python
Copy
Ask AI
from openai import OpenAIfrom dotenv import load_dotenvimport os# Use .env to store your API key or paste it directly into the codeload_dotenv()client = OpenAI( base_url="https://api.exa.ai", api_key=os.getenv('EXA_API_KEY'),)completion = client.chat.completions.create( model="exa", # or exa-pro messages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What are the latest developments in quantum computing?"}], extra_body={ "text": True })print(completion.choices[0].message.content)
Find similar links to a given URL and get the full text for each link.
python
Copy
Ask AI
from exa_py import Exafrom dotenv import load_dotenvimport osload_dotenv()exa = Exa(os.getenv('EXA_API_KEY'))# get similar links to this post about AGIresult = exa.find_similar( "https://amistrongeryet.substack.com/p/are-we-on-the-brink-of-agi", exclude_domains = ["amistrongeryet.substack.com"], num_results = 3)urls = [link_data.url for link_data in result.results]# get full text for each urlweb_pages = exa.get_contents( urls, text=True)for web_page in web_pages.results: print(f"URL: {web_page.url}") print(f"Text snippet: {web_page.text[:500]} ...") print("-"*100)
Install the python SDKs with pip. If you want to store your API key in a .env file, make sure to install the dotenv library.
Once you’ve installed the SDKs, create a file called exa.py and add the code below.
Get a list of results and their full text content.
python
Copy
Ask AI
from exa_py import Exafrom dotenv import load_dotenvimport os# Use .env to store your API key or paste it directly into the codeload_dotenv()exa = Exa(os.getenv('EXA_API_KEY'))result = exa.search_and_contents( "An article about the state of AGI", type="auto", text=True,)print(result)
Get a list of results and their full text content.
python
Copy
Ask AI
from exa_py import Exafrom dotenv import load_dotenvimport os# Use .env to store your API key or paste it directly into the codeload_dotenv()exa = Exa(os.getenv('EXA_API_KEY'))result = exa.search_and_contents( "An article about the state of AGI", type="auto", text=True,)print(result)
Get an answer to a question, grounded by citations from exa.
python
Copy
Ask AI
from exa_py import Exafrom dotenv import load_dotenvimport os# Use .env to store your API key or paste it directly into the codeload_dotenv()exa = Exa(os.getenv('EXA_API_KEY'))result = exa.stream_answer( "What are the latest findings on gut microbiome's influence on mental health?", text=True,)for chunk in result: print(chunk, end='', flush=True)
Get a chat completion from exa.
python
Copy
Ask AI
from openai import OpenAIfrom dotenv import load_dotenvimport os# Use .env to store your API key or paste it directly into the codeload_dotenv()client = OpenAI( base_url="https://api.exa.ai", api_key=os.getenv('EXA_API_KEY'),)completion = client.chat.completions.create( model="exa", # or exa-pro messages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What are the latest developments in quantum computing?"}], extra_body={ "text": True })print(completion.choices[0].message.content)
Find similar links to a given URL and get the full text for each link.
python
Copy
Ask AI
from exa_py import Exafrom dotenv import load_dotenvimport osload_dotenv()exa = Exa(os.getenv('EXA_API_KEY'))# get similar links to this post about AGIresult = exa.find_similar( "https://amistrongeryet.substack.com/p/are-we-on-the-brink-of-agi", exclude_domains = ["amistrongeryet.substack.com"], num_results = 3)urls = [link_data.url for link_data in result.results]# get full text for each urlweb_pages = exa.get_contents( urls, text=True)for web_page in web_pages.results: print(f"URL: {web_page.url}") print(f"Text snippet: {web_page.text[:500]} ...") print("-"*100)
Install the javascript SDK with npm. If you want to store your API key in a .env file, make sure to install the dotenv library.
Once you’ve installed the SDK, create a file called exa.ts and add the code below.
Get a list of results and their full text content.
javascript
Copy
Ask AI
import dotenv from 'dotenv';import Exa from 'exa-js';dotenv.config();const exa = new Exa(process.env.EXA_API_KEY);const result = await exa.searchAndContents( "An article about the state of AGI", { type: "auto", text: true });// print the first resultconsole.log(result.results[0]);
Get a list of results and their full text content.
javascript
Copy
Ask AI
import dotenv from 'dotenv';import Exa from 'exa-js';dotenv.config();const exa = new Exa(process.env.EXA_API_KEY);const result = await exa.searchAndContents( "An article about the state of AGI", { type: "auto", text: true });// print the first resultconsole.log(result.results[0]);
Get an answer to a question, grounded by citations from exa.
javascript
Copy
Ask AI
import dotenv from 'dotenv';import Exa from 'exa-js';dotenv.config();const exa = new Exa(process.env.EXA_API_KEY);for await (const chunk of exa.streamAnswer( "What is the population of New York City?", { text: true })) { if (chunk.content) { process.stdout.write(chunk.content); } if (chunk.citations) { console.log("\nCitations:", chunk.citations); }}
Get a chat completion from exa.
javascript
Copy
Ask AI
import OpenAI from "openai";import dotenv from 'dotenv';import Exa from 'exa-js';dotenv.config();const openai = new OpenAI({ baseURL: "https://api.exa.ai", apiKey: process.env.EXA_API_KEY,});async function main() {const completion = await openai.chat.completions.create({ model: "exa", // or exa-pro messages: [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What are the latest developments in quantum computing?"} ], store: true, stream: true, extra_body: { text: true // include full text from sources }});for await (const chunk of completion) { console.log(chunk.choices[0].delta.content); }}main();
Find similar links to a given URL and get the full text for each link.
javascript
Copy
Ask AI
import Exa from 'exa-js';import dotenv from 'dotenv';dotenv.config();const exa = new Exa(process.env.EXA_API_KEY);// Find similar links to this post about AGIconst result = await exa.findSimilar( "https://amistrongeryet.substack.com/p/are-we-on-the-brink-of-agi", { excludeDomains: ["amistrongeryet.substack.com"], numResults: 3 });const urls = result.results.map(linkData => linkData.url);// Get full text for each URLconst webPages = await exa.getContents(urls, { text: true });webPages.results.forEach(webPage => { console.log(`URL: ${webPage.url}`); console.log(`Text snippet: ${webPage.text.slice(0, 500)} ...`); console.log("-".repeat(100));});
Pass one of the following commands to your terminal to make an API request.
Get a list of results and their full text content.
bash
Copy
Ask AI
curl --request POST \ --url https://api.exa.ai/search \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --header "x-api-key: ${EXA_API_KEY}" \ --data '{ "query": "An article about the state of AGI", "type": "auto", "contents": { "text": true }}'
Get a list of results and their full text content.
bash
Copy
Ask AI
curl --request POST \ --url https://api.exa.ai/search \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --header "x-api-key: ${EXA_API_KEY}" \ --data '{ "query": "An article about the state of AGI", "type": "auto", "contents": { "text": true }}'
Get an answer to a question, grounded by citations from exa.
bash
Copy
Ask AI
curl --request POST \ --url https://api.exa.ai/answer \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --header "x-api-key: ${EXA_API_KEY}" \ --data "{ \"query\": \"What are the latest findings on gut microbiome's influence on mental health?\", \"text\": true }"
Get a chat completion from exa.
bash
Copy
Ask AI
curl https://api.exa.ai/chat/completions \ -H "Content-Type: application/json" \ -H "x-api-key: ${EXA_API_KEY}" \ -d '{ "model": "exa", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "What are the latest developments in quantum computing?" } ], "extra_body": { "text": true } }'