Skip to main content
PAS2 requires API keys from both Mistral AI and OpenAI to function. This guide shows you how to obtain and configure these keys.

Required API keys

PAS2 uses a dual-model architecture:
  • Mistral AI: For paraphrase generation and response generation (mistral-large-latest)
  • OpenAI: For hallucination detection judging (o3-mini)
Both API keys are required. PAS2 will raise a ValueError if either key is missing.

Getting your Mistral AI API key

1

Create a Mistral AI account

Visit Mistral AI and sign up for an account.
2

Navigate to API keys

Go to your dashboard and find the API keys section.
3

Generate a new API key

Click “Create new key” and copy the generated key. Store it securely.
4

Set the environment variable

Add the key to your .env file:
HF_MISTRAL_API_KEY=your_mistral_api_key_here

Getting your OpenAI API key

1

Create an OpenAI account

Visit OpenAI Platform and sign up for an account.
2

Navigate to API keys

Go to your account settings and select “API keys” from the menu.
3

Generate a new API key

Click “Create new secret key”, give it a name, and copy the key. This is your only chance to see the full key.
4

Set the environment variable

Add the key to your .env file:
HF_OPENAI_API_KEY=your_openai_api_key_here
OpenAI API keys are only shown once during creation. Store them securely in a password manager.

Setting up environment variables

Local development

Create a .env file in your project root:
.env
HF_MISTRAL_API_KEY=your_mistral_api_key_here
HF_OPENAI_API_KEY=your_openai_api_key_here
PAS2 automatically loads these variables using python-dotenv.

Hugging Face Spaces deployment

1

Open your Space settings

Navigate to your Space on Hugging Face and click on “Settings”.
2

Add secrets

Scroll to the “Repository secrets” section.
3

Create secret variables

Add two new secrets:
  • Name: HF_MISTRAL_API_KEY, Value: your Mistral API key
  • Name: HF_OPENAI_API_KEY, Value: your OpenAI API key
4

Restart your Space

The Space will automatically restart and load the new secrets.
Never commit API keys to your repository. Always use environment variables or secrets management.

Passing API keys programmatically

You can also pass API keys directly when initializing PAS2:
from pas2 import PAS2

pas2 = PAS2(
    mistral_api_key="your_mistral_api_key",
    openai_api_key="your_openai_api_key"
)
This method takes priority over environment variables but is less secure for production use.

Verifying API key configuration

Test your API key setup:
from pas2 import PAS2
import os

try:
    # Try initializing with environment variables
    pas2 = PAS2(
        mistral_api_key=os.environ.get("HF_MISTRAL_API_KEY"),
        openai_api_key=os.environ.get("HF_OPENAI_API_KEY")
    )
    print("API keys configured successfully!")
except ValueError as e:
    print(f"Configuration error: {e}")

Troubleshooting

Missing API key errors

If you see:
ValueError: Mistral API key is required. Set it via HF_MISTRAL_API_KEY...
Check that:
  • Your .env file exists and is in the correct location
  • The variable names are spelled correctly (HF_MISTRAL_API_KEY, HF_OPENAI_API_KEY)
  • There are no extra spaces or quotes around the keys

API authentication errors

If you see authentication errors when making API calls:
  • Verify your API keys are valid and active
  • Check that you have available credits/quota on both platforms
  • Ensure the keys haven’t expired or been revoked

API costs and rate limits

Be aware of API costs. Each query generates multiple API calls:
  • 1 call for paraphrase generation (Mistral)
  • N+1 calls for responses (Mistral, where N = number of paraphrases)
  • 1 call for hallucination judging (OpenAI)
Monitor your usage:

Next steps

Build docs developers (and LLMs) love