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.choices[0].message.content)  # print the response content
2

Replace the base URL with api.exa.ai

Exa will parse 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", # use exa as the base url
  api_key="YOUR_EXA_API_KEY", # update your 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?"}
],

# use extra_body to pass extra parameters to the /answer endpoint
  extra_body={
    "text": True # include full text from sources
  }
)

print(completion.choices[0].message.content)  # print the response content
print(completion.choices[0].message.citations)  # print the citations