> ## Documentation Index
> Fetch the complete documentation index at: https://hanabiaiinc-docs-concurrency-qpm-rate-limits.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Configure API authentication for the Fish Audio Python SDK

## Get Your API Key

<AccordionGroup>
  <Accordion icon="user-plus" title="Create a Fish Audio account">
    Sign up for a free Fish Audio account to get started with our API.

    1. Go to [fish.audio/auth/signup](https://fish.audio/auth/signup)
    2. Fill in your details to create an account, complete steps to verify your account.
    3. Log in to your account and navigate to the [API section](https://fish.audio/app/api-keys)
  </Accordion>

  <Accordion icon="key" title="Get your API key">
    Once you have an account, you'll need an API key to authenticate your requests.

    1. Log in to your [Fish Audio Dashboard](https://fish.audio/app/api-keys/)
    2. Navigate to the API Keys section
    3. Click "Create New Key" and give it a descriptive name, set a expiration if desired
    4. Copy your key and store it securely

    <Warning>Keep your API key secret! Never commit it to version control or share it publicly.</Warning>
  </Accordion>
</AccordionGroup>

## Client Initialization

Initialize the [`FishAudio`](/api-reference/sdk/python/client#fishaudio-objects) client with your API key:

<Tabs>
  <Tab title="Environment Variable (Recommended)">
    The most secure approach is using environment variables:

    ```python theme={null}
    from fishaudio import FishAudio

    # Automatically reads from FISH_API_KEY environment variable
    client = FishAudio()
    ```

    Set the environment variable in your shell:

    ```bash theme={null}
    export FISH_API_KEY=your_api_key_here
    ```

    Or create a `.env` file in your project root:

    ```bash theme={null}
    FISH_API_KEY=your_api_key_here
    ```

    Then load it using `python-dotenv`:

    ```python theme={null}
    from dotenv import load_dotenv
    from fishaudio import FishAudio

    # Load environment variables from .env file
    load_dotenv()

    client = FishAudio()
    ```

    <Tip>
      Using environment variables keeps your API key out of your codebase and makes it easy to use different keys for development and production.
    </Tip>
  </Tab>

  <Tab title="Direct API Key">
    Provide the API key directly when initializing the client:

    ```python theme={null}
    from fishaudio import FishAudio

    client = FishAudio(api_key="your_api_key_here")
    ```

    <Warning>
      This approach is less secure. Never commit code containing your actual API key. Use this only for quick testing or when loading the key from a secure secrets manager.
    </Warning>
  </Tab>

  <Tab title="Custom Base URL">
    If you're using a proxy or custom endpoint:

    ```python theme={null}
    from fishaudio import FishAudio

    client = FishAudio(
        api_key="your_api_key",
        base_url="https://your-proxy-domain.com"
    )
    ```

    This is useful for:

    * Corporate proxies
    * Development/staging environments
    * Self-hosted deployments
  </Tab>
</Tabs>

## Verifying Authentication

Test your authentication by making a simple API call to check your account credits:

```python focus={7-9} theme={null}
from fishaudio import FishAudio
from fishaudio.exceptions import AuthenticationError

try:
    client = FishAudio()

    # Check account credits (requires valid authentication)
    credits = client.account.get_credits()
    print(f"Authentication successful! Credits: {credits.credit}")

except AuthenticationError:
    print("Authentication failed. Check your API key.")
```

Handle [`AuthenticationError`](/api-reference/sdk/python/exceptions#authenticationerror-objects) when verifying authentication. The example uses [`get_credits()`](/api-reference/sdk/python/resources#get_credits) to verify the authentication works.

## Next Steps

<CardGroup cols={2}>
  <Card title="Text-to-Speech" icon="microphone" href="/features/text-to-speech">
    Generate speech with the authenticated client
  </Card>

  <Card title="Voice Cloning" icon="clone" href="/features/voice-cloning">
    Clone voices and create custom models
  </Card>

  <Card title="Account Management" icon="user" href="/api-reference/sdk/python/resources#account">
    Check credits and manage your account
  </Card>

  <Card title="Error Handling" icon="triangle-exclamation" href="/api-reference/sdk/python/exceptions">
    Handle authentication errors properly
  </Card>
</CardGroup>
