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

# Getting Started

> Quick setup and initialization guide for Nevermined Payment Libraries

This guide will help you set up and initialize the Nevermined Payment Libraries to start monetizing your AI services.

## Prerequisites

Before you begin, make sure you have:

<Steps>
  <Step title="Development Environment">
    * Node.js 16+ and npm/yarn (for TypeScript)
    * Python 3.8+ (for Python)
    * A code editor (VS Code recommended)
  </Step>

  <Step title="Blockchain Wallet (for crypto payments)">
    * MetaMask or compatible wallet
    * Some test tokens for the testing environment
    * Note: Not required for fiat-only payment flows
  </Step>

  <Step title="Nevermined API Key">
    Get your API key from the [Nevermined App](https://app.nevermined.io)
  </Step>
</Steps>

## Installation

<Tabs>
  <Tab title="TypeScript/JavaScript">
    ```bash theme={null}
    npm install @nevermined-io/payments
    # or
    yarn add @nevermined-io/payments
    ```
  </Tab>

  <Tab title="Python">
    ```bash theme={null}
    pip install payments-py
    ```
  </Tab>
</Tabs>

## Getting Your API Key

1. Go to the [Nevermined App](https://app.nevermined.io)
2. Log in with your wallet
3. Navigate to the **Settings** section in the user menu
4. Click on the **API Keys** tab
5. Generate a new key, give it a descriptive name, and copy it
6. Store this key securely as an environment variable (e.g., `NVM_API_KEY`)

<Warning>
  Never expose your API key in client-side code or commit it to version control. Always use environment variables.
</Warning>

## Initialize the SDK

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    import { Payments } from '@nevermined-io/payments'

    const payments = Payments.getInstance({
      nvmApiKey: process.env.NVM_API_KEY,
      environment: 'testing' // or 'production'
    })
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from payments_py import Payments
    import os

    payments = Payments(
        api_key=os.environ.get('NVM_API_KEY'),
        environment='testing'  # or 'production'
    )
    ```
  </Tab>
</Tabs>

## Environment Configuration

Choose the appropriate environment for your use case:

<AccordionGroup>
  <Accordion title="Testing Environment">
    * **Network**: Base Sepolia testnet
    * **Use case**: Development and testing
    * **Tokens**: Test tokens (free)
    * **Environment**: `'testing'`
  </Accordion>

  <Accordion title="Production Environment">
    * **Network**: Base Mainnet
    * **Use case**: Live applications
    * **Tokens**: Real tokens (paid)
    * **Environment**: `'production'`
  </Accordion>
</AccordionGroup>

## Basic Configuration Example

Here's a complete example of setting up the Payments client:

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    import { Payments } from '@nevermined-io/payments'
    import dotenv from 'dotenv'

    // Load environment variables
    dotenv.config()

    // Initialize the Payments client
    const payments = Payments.getInstance({
      nvmApiKey: process.env.NVM_API_KEY!,
      environment: 'testing', // Start with testing
      // Optional: specify custom RPC endpoints
      // web3ProviderUri: 'https://your-custom-rpc-endpoint.com'
    })

    // Verify the connection
    console.log('Payments client initialized successfully')
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from payments_py import Payments
    import os
    from dotenv import load_dotenv

    # Load environment variables
    load_dotenv()

    # Initialize the Payments client
    payments = Payments(
        api_key=os.environ.get('NVM_API_KEY'),
        environment='testing',  # Start with testing
        # Optional: specify custom RPC endpoints
        # web3_provider_uri='https://your-custom-rpc-endpoint.com'
    )

    print('Payments client initialized successfully')
    ```
  </Tab>
</Tabs>

## Environment Variables Setup

Create a `.env` file in your project root:

```bash theme={null}
# Required
NVM_API_KEY=your_api_key_here

# Optional - for custom configurations
WEB3_PROVIDER_URI=https://your-custom-rpc-endpoint.com
BUILDER_ADDRESS=your_wallet_address_here
```

## Verification

Test your setup with a simple verification:

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    async function verifySetup() {
      try {
        // Test the connection by checking if the client is properly initialized
        const config = await payments.getConfig()
        console.log('Setup verified! Environment:', config.environment)
        return true
      } catch (error) {
        console.error('Setup verification failed:', error)
        return false
      }
    }

    verifySetup()
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    def verify_setup():
        try:
            # Test the connection by checking if the client is properly initialized
            config = payments.get_config()
            print(f'Setup verified! Environment: {config["environment"]}')
            return True
        except Exception as error:
            print(f'Setup verification failed: {error}')
            return False

    verify_setup()
    ```
  </Tab>
</Tabs>

## Next Steps

Now that you have the Nevermined Payment Libraries set up, you can:

<CardGroup cols={2}>
  <Card title="Create Your First Agent" icon="robot" href="/integration-guide/registration">
    Learn how to create AI agents and payment plans
  </Card>

  <Card title="Explore Use Cases" icon="lightbulb" href="/integration-guide/what-can-you-do">
    Discover what you can build with Nevermined
  </Card>

  <Card title="View Code Examples" icon="code" href="/introduction/example-apps">
    See complete implementation examples
  </Card>

  <Card title="Best Practices" icon="shield" href="/introduction/best-practices">
    Learn security and optimization tips
  </Card>
</CardGroup>

## Common Issues

<AccordionGroup>
  <Accordion title="Invalid API Key Error">
    Make sure your API key is correctly set in your environment variables and has the proper permissions.
  </Accordion>

  <Accordion title="Network Connection Issues">
    Check that you're using the correct environment ('testing' or 'production') and that your network connection is stable.
  </Accordion>

  <Accordion title="Wallet Connection Problems">
    Ensure your wallet has some test tokens for the testing environment or real tokens for production.
  </Accordion>
</AccordionGroup>

If you encounter any issues, check our [Troubleshooting Guide](/introduction/troubleshooting) or reach out to our community on [Discord](https://discord.gg/nevermined).
