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

# SDKs

> Official and community SDKs for the Unleeshed API

## Official SDKs

<Note>
  Official SDKs are coming soon! In the meantime, use the REST API directly.
</Note>

### JavaScript/TypeScript (Coming Soon)

```bash theme={null}
npm install @unleeshed/sdk
```

```typescript theme={null}
import { UnleeshedClient } from '@unleeshed/sdk';

const client = new UnleeshedClient({
  apiKey: process.env.UNLEESHED_API_KEY
});

const personas = await client.personas.list();
const topic = await client.topics.create({
  content: 'Should the Lakers trade AD?',
  personaIds: personas.map(p => p.id)
});

const result = await client.topics.waitForCommentaries(topic.topicId);
```

### Python (Coming Soon)

```bash theme={null}
pip install unleeshed
```

```python theme={null}
from unleeshed import UnleeshedClient

client = UnleeshedClient(api_key=os.environ["UNLEESHED_API_KEY"])

personas = client.personas.list()
topic = client.topics.create(
    content="Should the Lakers trade AD?",
    persona_ids=[p.id for p in personas]
)

result = client.topics.wait_for_commentaries(topic.topic_id)
```

## REST API Client Example

Until official SDKs are available, here's a simple client implementation:

<CodeGroup>
  ```javascript JavaScript theme={null}
  class UnleeshedClient {
    constructor(apiKey) {
      this.apiKey = apiKey;
      this.baseUrl = 'https://prod.api.unleeshed.ai/partner/v1';
    }
    
    async request(path, options = {}) {
      const response = await fetch(`${this.baseUrl}${path}`, {
        ...options,
        headers: {
          'X-Api-Key': this.apiKey,
          'Content-Type': 'application/json',
          ...options.headers
        }
      });
      
      const data = await response.json();
      if (!response.ok) {
        throw new Error(data.error?.message || 'Request failed');
      }
      return data;
    }
    
    async getPersonas() {
      return this.request('/personas');
    }
    
    async createTopic(content, personaIds, outputTypes = ['text']) {
      return this.request('/topics', {
        method: 'POST',
        body: JSON.stringify({
          content,
          persona_ids: personaIds,
          output_types: outputTypes
        })
      });
    }
    
    async getTopic(topicId) {
      return this.request(`/topics/${topicId}`);
    }
    
    async getCommentaries(topicId) {
      return this.request(`/topics/${topicId}/commentaries`);
    }
  }
  ```

  ```python Python theme={null}
  import requests
  import time

  class UnleeshedClient:
      def __init__(self, api_key):
          self.api_key = api_key
          self.base_url = "https://prod.api.unleeshed.ai/partner/v1"
      
      def _request(self, method, path, **kwargs):
          headers = {
              "X-Api-Key": self.api_key,
              "Content-Type": "application/json",
              **kwargs.pop("headers", {})
          }
          
          response = requests.request(
              method,
              f"{self.base_url}{path}",
              headers=headers,
              **kwargs
          )
          
          data = response.json()
          if not response.ok:
              raise Exception(data.get("error", {}).get("message", "Request failed"))
          return data
      
      def get_personas(self):
          return self._request("GET", "/personas")
      
      def create_topic(self, content, persona_ids, output_types=None):
          return self._request("POST", "/topics", json={
              "content": content,
              "persona_ids": persona_ids,
              "output_types": output_types or ["text"]
          })
      
      def get_topic(self, topic_id):
          return self._request("GET", f"/topics/{topic_id}")
      
      def get_commentaries(self, topic_id):
          return self._request("GET", f"/topics/{topic_id}/commentaries")
      
      def wait_for_commentaries(self, topic_id, timeout=180, poll_interval=10):
          start = time.time()
          while time.time() - start < timeout:
              result = self.get_topic(topic_id)
              if result["data"]["status"] == "completed":
                  return result
              time.sleep(poll_interval)
          raise TimeoutError("Timeout waiting for commentaries")
  ```
</CodeGroup>

## OpenAPI Specification

Generate your own client from our OpenAPI spec:

```bash theme={null}
# Download the spec
curl https://prod.api.unleeshed.ai/openapi.json -o openapi.json

# Generate TypeScript client
npx openapi-generator-cli generate \
  -i openapi.json \
  -g typescript-fetch \
  -o ./unleeshed-client

# Generate Python client
openapi-generator-cli generate \
  -i openapi.json \
  -g python \
  -o ./unleeshed-client
```

## Community SDKs

Have you built an SDK? [Let us know](mailto:developers@unleeshed.ai) and we'll list it here!
