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

# Authentication

> Complete guide to CheckThat AI API authentication using provider API keys

## Overview

CheckThat AI provides unified access to multiple AI providers through their existing API keys. Instead of creating new API keys, you use your existing keys from OpenAI, Anthropic, Google, xAI, or Together AI to access their models through our platform.

<Warning>
  **Keep your provider API keys secure!** Never expose any API keys in client-side code, public repositories, or unsecured locations. Treat them like passwords.
</Warning>

## Provider API Keys

CheckThat AI requires API keys from the specific providers whose models you want to use:

<Steps>
  <Step title="Choose your providers">
    Decide which AI providers you want to use:

    * **OpenAI**: GPT-4o, GPT-5, o3, o4-mini
    * **Anthropic**: Claude Sonnet 4, Sonnet Opus 4.1
    * **Google**: Gemini 2.5 Pro, Gemini 2.5 Flash
    * **xAI**: Grok 4, Grok 3, Grok 3 Mini
    * **Together AI**: Llama 3.3 70B, Deepseek models
  </Step>

  <Step title="Get provider API keys">
    Obtain API keys from your chosen providers:

    <CardGroup cols={2}>
      <Card title="OpenAI" icon="robot" href="https://platform.openai.com/api-keys">
        Create API key at platform.openai.com
      </Card>

      <Card title="Anthropic" icon="brain" href="https://console.anthropic.com">
        Get API key from console.anthropic.com
      </Card>

      <Card title="Google AI" icon="google" href="https://ai.google.dev">
        Generate key at ai.google.dev
      </Card>

      <Card title="xAI" icon="x" href="https://x.ai">
        Obtain key from x.ai platform
      </Card>
    </CardGroup>
  </Step>

  <Step title="Set environment variables">
    Store your API keys securely as environment variables:

    ```bash theme={null}
    export OPENAI_API_KEY="sk-proj-your-openai-key"
    export ANTHROPIC_API_KEY="sk-ant-your-anthropic-key"
    export GEMINI_API_KEY="your-gemini-api-key"
    export XAI_API_KEY="your-xai-api-key"
    export TOGETHER_API_KEY="your-together-api-key"
    ```
  </Step>

  <Step title="Test your setup">
    Verify your setup using the Python SDK:

    ```python theme={null}
    from checkthat_ai import CheckThatAI

    # Test with OpenAI
    client = CheckThatAI(api_key=os.getenv("OPENAI_API_KEY"))
    models = client.models.list()
    print("Available models:", len(models.models_list))
    ```
  </Step>
</Steps>

## Authentication Methods

You can provide your provider API keys in several ways when using CheckThat AI:

<Tabs>
  <Tab title="Python SDK (Recommended)">
    Use the CheckThat AI Python SDK with your provider API key:

    ```python theme={null}
    from checkthat_ai import CheckThatAI
    import os

    # Initialize with provider API key
    client = CheckThatAI(api_key=os.getenv("OPENAI_API_KEY"))

    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": "Hello!"}]
    )
    ```

    <Check>
      ### Recommended: The SDK automatically handles authentication and provides the best developer experience.
    </Check>
  </Tab>

  <Tab title="Direct API Calls">
    Include your provider API key directly in the request body:

    ```bash theme={null}
    curl -X POST 'https://api.checkthat-ai.com/v1/chat/completions' \
      -H 'Content-Type: application/json' \
      -d '{
        "api_key": "your-openai-api-key",
        "model": "gpt-4o",
        "messages": [{"role": "user", "content": "Hello!"}]
      }'
    ```

    <Info>
      ### Direct Integration: Useful for custom implementations or when the SDK isn't available.
    </Info>
  </Tab>

  <Tab title="Environment Variables">
    Set provider keys as environment variables:

    ```bash theme={null}
    # In your shell or .env file
    export OPENAI_API_KEY="sk-proj-your-key"
    export ANTHROPIC_API_KEY="sk-ant-your-key"

    # Then use in your application
    client = CheckThatAI(api_key=os.getenv("OPENAI_API_KEY"))
    ```
  </Tab>
</Tabs>

## Security Best Practices

<CardGroup cols={2}>
  <Card title="Environment Variables" icon="shield-check">
    Store API keys in environment variables, never in code:

    <Tip>
      Security Best Practice: Environment variables keep keys out of your source code.
    </Tip>

    ```bash theme={null}
    export CHECKTHAT_API_KEY="sk-checkthat-your-key-here"
    ```
  </Card>

  <Card title="Separate Keys" icon="key">
    Use different API keys for different environments:

    * Development: `CHECKTHAT_DEV_KEY`
    * Staging: `CHECKTHAT_STAGING_KEY`
    * Production: `CHECKTHAT_PROD_KEY`
  </Card>

  <Card title="Key Rotation" icon="arrows-rotate">
    Regularly rotate your API keys:

    * Create new key
    * Update applications
    * Revoke old key
  </Card>

  <Card title="Access Control" icon="users">
    Limit key access within your team:

    * Use key management systems
    * Implement least-privilege access
    * Monitor key usage
  </Card>
</CardGroup>

### Environment Variable Usage

<CodeGroup>
  ```javascript theme={null}
  const apiKey = process.env.CHECKTHAT_API_KEY;

  const response = await fetch('https://api.checkthat-ai.com/chat', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${apiKey}`
    },
    body: JSON.stringify({
      user_query: 'Your claim here',
      model: 'gpt-4'
    })
  });
  ```

  ```python theme={null}
  import os
  import requests

  api_key = os.getenv('CHECKTHAT_API_KEY')

  response = requests.post(
      'https://api.checkthat-ai.com/chat',
      headers={
          'Authorization': f'Bearer {api_key}',
          'Content-Type': 'application/json'
      },
      json={
          'user_query': 'Your claim here',
          'model': 'gpt-4'
      }
  )
  ```
</CodeGroup>

### Configuration Files

<Tabs>
  <Tab title=".env file">
    ```bash theme={null}
    # .env
    CHECKTHAT_API_KEY=sk-checkthat-1234567890abcdef
    CHECKTHAT_BASE_URL=https://api.checkthat-ai.com
    ```

    <Warning>
      **Never commit .env files to version control!** Add `.env` to your `.gitignore` file.
    </Warning>
  </Tab>

  <Tab title="Docker Compose">
    ```yaml theme={null}
    # docker-compose.yml
    services:
      app:
        environment:
          - CHECKTHAT_API_KEY=${CHECKTHAT_API_KEY}
        env_file:
          - .env
    ```
  </Tab>

  <Tab title="Kubernetes Secret">
    ```yaml theme={null}
    # secret.yaml
    apiVersion: v1
    kind: Secret
    metadata:
      name: checkthat-api-secret
    data:
      api-key: <base64-encoded-key>
    ```
  </Tab>
</Tabs>

## Error Responses

When authentication fails, the API returns specific error responses:

### Missing API Key

<ResponseExample>
  ```json 401 Unauthorized theme={null}
  {
    "detail": "API key is required"
  }
  ```
</ResponseExample>

### Invalid API Key

<ResponseExample>
  ```json 401 Unauthorized   theme={null}
  {
    "detail": "Invalid API key"
  }
  ```
</ResponseExample>

### Expired/Revoked Key

<ResponseExample>
  ```json 401 Unauthorized theme={null}
  {
    "detail": "API key has been revoked or expired"
  }
  ```
</ResponseExample>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Authentication failing despite correct key">
    **Common causes:**

    * Whitespace in API key (trim the key)
    * Wrong header format (ensure "Bearer " prefix)
    * Key copied incorrectly (verify character count)
    * Environment variable not loaded

    **Solution:**

    ```bash theme={null}
    # Test your key directly
    curl -v -H "Authorization: Bearer $(echo $CHECKTHAT_API_KEY | tr -d '[:space:]')" \
      https://api.checkthat-ai.com/health
    ```
  </Accordion>

  <Accordion title="Intermittent authentication errors">
    **Possible causes:**

    * Network issues causing header corruption
    * Load balancer configuration problems
    * Concurrent requests with rate limiting

    **Solution:**
    Implement retry logic with exponential backoff for 401 errors.
  </Accordion>

  <Accordion title="Different behavior between environments">
    **Common issues:**

    * Different API keys with different permissions
    * Environment variables not set correctly
    * Different base URLs

    **Solution:**

    ```bash theme={null}
    # Verify environment configuration
    echo "API Key: ${CHECKTHAT_API_KEY:0:20}..."
    echo "Base URL: $CHECKTHAT_BASE_URL"
    ```
  </Accordion>
</AccordionGroup>

## Rate Limiting and API Keys

Each API key has associated rate limits based on your subscription plan:

<CardGroup cols={3}>
  <Card title="Free Tier" icon="gift">
    * 100 requests/hour
    * 1,000 requests/month
    * Basic model access
  </Card>

  <Card title="Pro Plan" icon="rocket">
    * 1,000 requests/hour
    * 50,000 requests/month
    * All models available
  </Card>

  <Card title="Enterprise" icon="building">
    * Custom limits
    * Dedicated support
    * SLA guarantees
  </Card>
</CardGroup>

<Tip>
  Monitor the following response headers to track your usage:

  * `X-RateLimit-Limit`: Your rate limit
  * `X-RateLimit-Remaining`: Requests remaining
  * `X-RateLimit-Reset`: When limit resets
</Tip>

## Need Help?

If you're experiencing authentication issues:

1. **Check your implementation** against the examples above
2. **Test with the Python SDK** using the provided examples
3. **Contact support** at [kadapalanikhil@gmail.com](mailto:kadapalanikhil@gmail.com)
4. **Report issues** on [GitHub](https://github.com/nikhil-kadapala/checkthat-ai/issues)

<Warning>
  When contacting support, **never include your actual API key**. Instead, provide only the prefix (e.g., "sk-proj-..." or "sk-ant-...") and describe the issue.
</Warning>
