Skip to content
Dashboard

SDKs & Resources

Client libraries and tools for interacting with the Brainpercent API.

JavaScript / TypeScript

A lightweight wrapper around the REST API using fetch:

class BrainpercentClient {
  constructor(apiKey) {
    this.apiKey = apiKey;
    this.baseUrl = 'https://brainpercent.app/api/v1';
  }

  async request(path, options = {}) {
    const response = await fetch(`${this.baseUrl}${path}`, {
      ...options,
      headers: {
        'Authorization': `Bearer ${this.apiKey}`,
        'Content-Type': 'application/json',
        ...options.headers,
      },
    });
    return response.json();
  }

  // Articles
  listArticles(params) {
    const qs = new URLSearchParams(params).toString();
    return this.request(`/articles?${qs}`);
  }

  getArticle(id) {
    return this.request(`/articles/${id}`);
  }

  generateArticle(body) {
    return this.request('/articles/generate', {
      method: 'POST',
      body: JSON.stringify(body),
    });
  }

  getArticleStatus(id) {
    return this.request(`/articles/${id}/status`);
  }

  // Credits
  getCredits() {
    return this.request('/user/credits');
  }
}

// Usage
const client = new BrainpercentClient('bp_your_key');
const articles = await client.listArticles({ page: 1, limit: 10 });

Python

A simple Python wrapper using requests:

import requests

class BrainpercentClient:
    def __init__(self, api_key: str):
        self.api_key = api_key
        self.base_url = "https://brainpercent.app/api/v1"
        self.session = requests.Session()
        self.session.headers.update({
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json",
        })

    def _request(self, method: str, path: str, **kwargs):
        response = self.session.request(method, f"{self.base_url}{path}", **kwargs)
        response.raise_for_status()
        return response.json()

    # Articles
    def list_articles(self, **params):
        return self._request("GET", "/articles", params=params)

    def get_article(self, article_id: str):
        return self._request("GET", f"/articles/{article_id}")

    def generate_article(self, topic: str, **kwargs):
        return self._request("POST", "/articles/generate", json={"topic": topic, **kwargs})

    def get_article_status(self, article_id: str):
        return self._request("GET", f"/articles/{article_id}/status")

    # Credits
    def get_credits(self):
        return self._request("GET", "/user/credits")


# Usage
client = BrainpercentClient("bp_your_key")
articles = client.list_articles(page=1, limit=10)

cURL

All examples in this documentation include cURL commands. Set your key as an environment variable for convenience:

export BP_API_KEY="bp_your_api_key_here"

# List articles
curl https://brainpercent.app/api/v1/articles \
  -H "Authorization: Bearer $BP_API_KEY"

# Generate an article
curl -X POST https://brainpercent.app/api/v1/articles/generate \
  -H "Authorization: Bearer $BP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"topic": "AI SEO Strategies", "tone": "professional"}'

# Check credits
curl https://brainpercent.app/api/v1/user/credits \
  -H "Authorization: Bearer $BP_API_KEY"

OpenAPI Specification

Download the full OpenAPI 3.0 specification for code generation, Postman import, or building your own client: