Official SDKs
Official SDKs are coming soon! In the meantime, use the REST API directly.
JavaScript/TypeScript (Coming Soon)
npm install @unleeshed/sdk
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)
pip install unleeshed
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: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`);
}
}
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")
OpenAPI Specification
Generate your own client from our OpenAPI spec:# 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