import os
from typing import Tuple

import requests


def get_saelens_release_and_id(
    neuronpedia_id: str, api_key: str = None
) -> Tuple[str, str]:

    # Set up the API request
    if api_key is None:
        api_key = os.environ.get("NEURONPEDIA_API_KEY")
        if not api_key:
            raise ValueError(
                "Please provide an API key or set NEURONPEDIA_API_KEY environment variable"
            )
    url = f"https://www.neuronpedia.org/api/feature/{neuronpedia_id}/0"
    headers = {"Authorization": f"Bearer {api_key}"}

    # Make the request
    response = requests.get(url, headers=headers)

    response_json = response.json()
    sae_lens_release = response_json["source"]["saelensRelease"]
    saelens_sae_id = response_json["source"]["saelensSaeId"]
    return sae_lens_release, saelens_sae_id
