> ## Documentation Index
> Fetch the complete documentation index at: https://exa.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Get started with Exa

> Make your first request to one of Exa's API endpoints

<Steps>
  <Step title="Set up your API key">
    Get your API key from the [Exa Dashboard](https://dashboard.exa.ai/login?redirect=/) and set it as an environment variable.

    For the Python or JavaScript SDK, create a file called `.env` in the root of your project and add the following line:

    ```bash .env theme={null}
    EXA_API_KEY=your api key without quotes
    ```

    For cURL, set it as an environment variable in your terminal instead:

    <Tabs>
      <Tab title="macOS/Linux">
        ```bash theme={null}
        export EXA_API_KEY="your-api-key"
        ```
      </Tab>

      <Tab title="Windows">
        ```powershell theme={null}
        setx EXA_API_KEY "your-api-key"
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Install the SDK">
    Install the SDK for your language. If you want to store your API key in a `.env` file, also install the dotenv library. cURL needs no installation, skip to the next step.

    <CodeGroup>
      ```bash Python theme={null}
      pip install exa-py
      pip install openai
      pip install python-dotenv
      ```

      ```bash JavaScript theme={null}
      npm install exa-js
      npm install openai
      npm install dotenv
      ```
    </CodeGroup>
  </Step>

  <Step title="Make your first request">
    Create a file (`exa.py` or `exa.ts`) with the code below, or run the cURL command directly. Pick a use case:

    <Tabs>
      <Tab title="Search and crawl">
        Get a list of results and their full text content.

        <CodeGroup>
          ```python Python theme={null}
          from exa_py import Exa
          from dotenv import load_dotenv

          import os

          # Use .env to store your API key or paste it directly into the code
          load_dotenv()
          exa = Exa(api_key=os.getenv('EXA_API_KEY'))

          result = exa.search(
            "An article about the state of AGI",
            type="auto",
            contents={"highlights": True}
          )

          print(result)
          ```

          ```javascript JavaScript theme={null}
          import dotenv from 'dotenv';
          import Exa from 'exa-js';

          dotenv.config();

          const exa = new Exa(process.env.EXA_API_KEY);

          const result = await exa.search(
            "An article about the state of AGI",
            {
              type: "auto",
              contents: {
                highlights: true
              }
            }
          );

          // print the first result
          console.log(result.results[0]);
          ```

          ```bash cURL theme={null}
          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": {
                "highlights": true
              }
          }'
          ```
        </CodeGroup>
      </Tab>

      <Tab title="Answer">
        Get an answer to a question, grounded by citations from exa.

        <CodeGroup>
          ```python Python theme={null}
          from exa_py import Exa
          from dotenv import load_dotenv

          import os

          # Use .env to store your API key or paste it directly into the code
          load_dotenv()
          exa = Exa(api_key=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)
          ```

          ```javascript JavaScript theme={null}
          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);
            }
          }
          ```

          ```bash cURL theme={null}
          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
            }"
          ```
        </CodeGroup>
      </Tab>

      <Tab title="Chat Completions">
        Get a chat completion from exa.

        <CodeGroup>
          ```python Python theme={null}
          from openai import OpenAI
          from dotenv import load_dotenv

          import os

          # Use .env to store your API key or paste it directly into the code
          load_dotenv()

          client = OpenAI(
            base_url="https://api.exa.ai",
            api_key=os.getenv('EXA_API_KEY'),
          )

          completion = client.chat.completions.create(
            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
            }
          )
          print(completion.choices[0].message.content)
          ```

          ```javascript JavaScript theme={null}
          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",
              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();
          ```

          ```bash cURL theme={null}
          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
              }
            }'
          ```
        </CodeGroup>
      </Tab>
    </Tabs>
  </Step>
</Steps>
