See the full /answer endpoint reference here.

Get Started

Get your Exa API key

1

An example of your existing openai chat completions code

python
from openai import OpenAI

client = OpenAI(api_key="YOUR_OPENAI_API_KEY")

completion = client.chat.completions.create(
  model="gpt-4o-mini",
  messages= [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What are the latest developments in quantum computing?"}
  ]
)

print(completion)
2

Replace the base URL with api.exa.ai

Exa willparse through your messages and send only the last message to the /answer endpoint.
python
from openai import OpenAI

client = OpenAI(
  base_url="https://api.exa.ai",
  api_key="YOUR_OPENAI_API_KEY",  # required by OpenAI client but not used
  default_headers={"x-api-key": "YOUR_EXA_API_KEY"}
)

completion = client.chat.completions.create(
  model="gpt-4o-mini", # required by OpenAI client but not used
  messages = [
  {"role": "system", "content": "You are a helpful assistant."},
  {"role": "user", "content": "What are the latest developments in quantum computing?"}
],

# use extra_body to pass parameters to the /answer endpoint
  extra_body={
    "mode": "accurate", # number of query variations to increase result coverage
    "text": True # include full text from sources
  }
)

print(completion)