assafelovic/gpt-researcher · error · Exception

GetXAPI API key not found. Please set the GETXAPI_API_KEY en

Error message

GetXAPI API key not found. Please set the GETXAPI_API_KEY environment variable. Get a key at https://getxapi.com

What it means

Exception raised by the GetXAPI retriever when the GETXAPI_API_KEY environment variable is missing (KeyError caught and re-raised with this message). The key is required to authenticate against the getxapi.com search API.

Source

Thrown at gpt_researcher/retrievers/getxapi/getxapi.py:28

    """
    GetXAPI X/Twitter search retriever.

    Searches tweets via the GetXAPI REST API and returns results in the
    standard {title, href, body} format used by all GPT Researcher retrievers.

    Set GETXAPI_API_KEY in your environment. Get one at https://getxapi.com
    """

    def __init__(self, query, query_domains=None, **kwargs):
        self.query = query
        self.query_domains = query_domains
        self.api_key = self.get_api_key()

    def get_api_key(self):
        try:
            api_key = os.environ["GETXAPI_API_KEY"]
        except KeyError:
            raise Exception(
                "GetXAPI API key not found. Please set the GETXAPI_API_KEY "
                "environment variable. Get a key at https://getxapi.com"
            )
        return api_key

    def search(self, max_results=10):
        """
        Search X/Twitter via GetXAPI advanced search.

        Returns:
            list: Search results as [{title, href, body}, ...]
        """
        print(f"Searching X/Twitter with query: {self.query}...")

        try:
            results = self._search_tweets(max_results)
            return results
        except Exception as e:

View on GitHub (pinned to 6f998577d5)

Solutions

  1. export GETXAPI_API_KEY=<key> (get one at https://getxapi.com).
  2. Add it to .env / secrets and confirm it loads before creating the retriever.
  3. Verify the variable name spelling in compose/CI configs.

Example fix

# before
retriever = GetXAPI(query="...")

# after
import os
assert os.environ.get("GETXAPI_API_KEY"), "Set GETXAPI_API_KEY"
retriever = GetXAPI(query="...")
Defensive patterns

Strategy: validation

Validate before calling

import os
if not os.environ.get("GETXAPI_API_KEY"):
    raise SystemExit("Set GETXAPI_API_KEY (https://getxapi.com)")

Type guard

null

Try / catch

try:
    retriever = GetXAPI(query)
except Exception as e:
    if "GETXAPI_API_KEY" in str(e):
        sys.exit(str(e))
    raise

Prevention

When it happens

Trigger: Instantiating the getxapi retriever, whose __init__ calls get_api_key(), with GETXAPI_API_KEY unset.

Common situations: Env var never set, .env file not loaded in the runtime process, or deployment environment missing the injected secret.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of assafelovic/gpt-researcher@6f998577d5 (2026-08-28). Data as JSON: /api/errors/109f9caf3190a093. Report an issue: GitHub.