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

# Development

> Set up your development environment for Quantum AI Agent integration

<Info>
  **Prerequisites**:

  * Programming language of choice (Python, JavaScript, etc.)
  * Valid Quantum API Bearer token
  * Access to the Quantum AI Agent system
</Info>

Follow these steps to set up your development environment for integrating with the Quantum AI Agent.

<Steps>
  <Step title="Install required dependencies">
    Choose your preferred programming language and install the necessary HTTP client libraries:

    <CodeGroup>
      ```bash Python theme={null}
      pip install requests
      pip install python-dotenv  # For environment variables
      ```

      ```bash JavaScript/Node.js theme={null}
      npm install axios
      npm install dotenv  # For environment variables
      ```

      ```bash cURL theme={null}
      # cURL is usually pre-installed on most systems
      curl --version
      ```
    </CodeGroup>
  </Step>

  <Step title="Set up environment variables">
    Create a `.env` file in your project root to store your API credentials securely:

    ```bash theme={null}
    QUANTUM_API_TOKEN=your_bearer_token_here
    QUANTUM_API_BASE_URL=https://www.cognivo.app/api/v1
    QUANTUM_AGENT_ID=5
    QUANTUM_COMPANY_ID=2
    QUANTUM_OWNER_ID=1
    ```

    <Warning>
      Never commit your `.env` file to version control. Add it to your `.gitignore`.
    </Warning>
  </Step>

  <Step title="Create your first integration">
    Set up a basic integration to test your connection to the Quantum AI Agent:

    <CodeGroup>
      ```python Python theme={null}
      import os
      import requests
      from dotenv import load_dotenv

      # Load environment variables
      load_dotenv()

      class QuantumAPIClient:
          def __init__(self):
              self.base_url = os.getenv('QUANTUM_API_BASE_URL')
              self.token = os.getenv('QUANTUM_API_TOKEN')
              self.headers = {
                  'Authorization': f'Bearer {self.token}',
                  'Content-Type': 'application/json'
              }
          
          def test_connection(self):
              """Test API connection"""
              try:
                  response = requests.get(f'{self.base_url}/test', headers=self.headers)
                  return response.status_code == 200
              except Exception as e:
                  print(f"Connection failed: {e}")
                  return False

      # Initialize client
      client = QuantumAPIClient()
      if client.test_connection():
          print("✅ Connected to Quantum AI Agent successfully!")
      else:
          print("❌ Failed to connect to Quantum AI Agent")
      ```

      ```javascript JavaScript theme={null}
      const axios = require('axios');
      require('dotenv').config();

      class QuantumAPIClient {
          constructor() {
              this.baseURL = process.env.QUANTUM_API_BASE_URL;
              this.token = process.env.QUANTUM_API_TOKEN;
              this.headers = {
                  'Authorization': `Bearer ${this.token}`,
                  'Content-Type': 'application/json'
              };
          }
          
          async testConnection() {
              try {
                  const response = await axios.get(`${this.baseURL}/test`, {
                      headers: this.headers
                  });
                  return response.status === 200;
              } catch (error) {
                  console.error('Connection failed:', error.message);
                  return false;
              }
          }
      }

      // Initialize client
      const client = new QuantumAPIClient();
      client.testConnection().then(success => {
          if (success) {
              console.log('✅ Connected to Quantum AI Agent successfully!');
          } else {
              console.log('❌ Failed to connect to Quantum AI Agent');
          }
      });
      ```
    </CodeGroup>
  </Step>

  <Step title="Test document upload">
    Create a simple test to upload a document to the Quantum AI Agent:

    <CodeGroup>
      ```python Python theme={null}
      import base64

      def upload_test_document(client):
          # Create a simple text document
          text_content = "Hello Quantum AI Agent! This is a test document."
          base64_content = base64.b64encode(text_content.encode()).decode()
          
          data = {
              "owner_id": int(os.getenv('QUANTUM_OWNER_ID')),
              "company_id": int(os.getenv('QUANTUM_COMPANY_ID')),
              "agent_id": int(os.getenv('QUANTUM_AGENT_ID')),
              "documents": [
                  {
                      "name": "test-document.txt",
                      "mimetype": "text/plain",
                      "base64": base64_content
                  }
              ]
          }
          
          response = requests.post(
              f'{client.base_url}/documents/create',
              headers=client.headers,
              json=data
          )
          
          return response.json()

      # Test upload
      result = upload_test_document(client)
      print("Upload result:", result)
      ```

      ```javascript JavaScript theme={null}
      async function uploadTestDocument(client) {
          // Create a simple text document
          const textContent = "Hello Quantum AI Agent! This is a test document.";
          const base64Content = Buffer.from(textContent).toString('base64');
          
          const data = {
              owner_id: parseInt(process.env.QUANTUM_OWNER_ID),
              company_id: parseInt(process.env.QUANTUM_COMPANY_ID),
              agent_id: parseInt(process.env.QUANTUM_AGENT_ID),
              documents: [
                  {
                      name: "test-document.txt",
                      mimetype: "text/plain",
                      base64: base64Content
                  }
              ]
          };
          
          try {
              const response = await axios.post(
                  `${client.baseURL}/documents/create`,
                  data,
                  { headers: client.headers }
              );
              return response.data;
          } catch (error) {
              console.error('Upload failed:', error.response?.data || error.message);
              return null;
          }
      }

      // Test upload
      uploadTestDocument(client).then(result => {
          console.log('Upload result:', result);
      });
      ```
    </CodeGroup>
  </Step>
</Steps>

## Best Practices

<CardGroup cols={2}>
  <Card title="Error Handling" icon="shield-exclamation">
    Always implement proper error handling for API calls. Check status codes and handle network failures gracefully.
  </Card>

  <Card title="Rate Limiting" icon="clock">
    Respect API rate limits. Implement exponential backoff for retries when encountering rate limit errors.
  </Card>

  <Card title="Security" icon="lock">
    Store API tokens securely using environment variables. Never hardcode credentials in your source code.
  </Card>

  <Card title="Logging" icon="file-text">
    Implement comprehensive logging to track API interactions and debug issues effectively.
  </Card>
</CardGroup>

## Development Tools

<AccordionGroup>
  <Accordion title="API Testing Tools">
    * **Postman**: Create and test API requests with a GUI
    * **Insomnia**: Lightweight REST client for API testing
    * **cURL**: Command-line tool for making HTTP requests
    * **HTTPie**: User-friendly command-line HTTP client
  </Accordion>

  <Accordion title="Code Examples Repository">
    Check out our [GitHub repository](https://github.com/quantum-ai/examples) for complete integration examples in multiple programming languages.
  </Accordion>

  <Accordion title="Development Environment">
    * Use virtual environments (Python) or package managers (Node.js)
    * Set up proper IDE configuration with API documentation
    * Configure debugging tools for API interactions
  </Accordion>
</AccordionGroup>

## Next Steps

Once you have your development environment set up:

1. **Explore the API**: Review the [API Documentation](/api-reference/introduction)
2. **Upload Documents**: Try the [Documents API](/api-reference/endpoint/documents-create)
3. **Build Your Integration**: Start developing your custom integration
4. **Test Thoroughly**: Ensure your integration handles all edge cases

<Note>
  Need help? Check our troubleshooting guide or contact support for assistance with your Quantum AI Agent integration.
</Note>

We suggest using extensions on your IDE to recognize and format MDX. If you're a VSCode user, consider the [MDX VSCode extension](https://marketplace.visualstudio.com/items?itemName=unifiedjs.vscode-mdx) for syntax highlighting, and [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) for code formatting.

## Troubleshooting

<AccordionGroup>
  <Accordion title="Error: Could not load the &#x22;sharp&#x22; module using the darwin-arm64 runtime">
    This may be due to an outdated version of node. Try the following:

    1. Remove the currently-installed version of the CLI: `npm remove -g mint`
    2. Upgrade to Node v19 or higher.
    3. Reinstall the CLI: `npm i -g mint`
  </Accordion>

  <Accordion title="Issue: Encountering an unknown error">
    Solution: Go to the root of your device and delete the `~/.mintlify` folder. Then run `mint dev` again.
  </Accordion>
</AccordionGroup>

Curious about what changed in the latest CLI version? Check out the [CLI changelog](https://www.npmjs.com/package/mintlify?activeTab=versions).
