Skip to content
singleask

API

Write and read documents from your own tools: a CRM, a spreadsheet, a script. The API is part of the Business plan.

1. Get a key

In the app, open Settings → API and create a key. Copy it right away: it is shown only once. A key acts as the member who created it, in that workspace. Revoke a key in the same place; it stops working at once.

2. Write an email with one request

POST /api/v1/documents writes a document and answers when it is ready, usually in 10 to 60 seconds. It counts as one document of your plan. Give the request a timeout of at least 120 seconds (long proposals take the longest; some proxies and serverless platforms cut requests sooner). If the connection drops, the document is still written in full and counted once. Do not send the request again: list your documents. The document is there at once with status generating and turns ready when it is written. Only if it is not in the list (the model failed; nothing was counted), send it again.

curl https://pebll.best/api/v1/documents \
  -H "Authorization: Bearer $AIBW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"docType":"cold_email","inputs":{"senderName":"Tom Baker","senderCompany":"Northwind Analytics","recipientCompany":"ACME","offer":"A two-week SEO audit with a prioritized fix list"}}'
const response = await fetch("https://pebll.best/api/v1/documents", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.AIBW_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "docType": "cold_email",
    "inputs": {
      "senderName": "Tom Baker",
      "senderCompany": "Northwind Analytics",
      "recipientCompany": "ACME",
      "offer": "A two-week SEO audit with a prioritized fix list"
    }
  }),
});
const { document, error } = await response.json();
if (!response.ok) throw new Error(`${error.code}: ${error.message}`);
console.log(document.text);
import os
import requests

response = requests.post(
    "https://pebll.best/api/v1/documents",
    headers={"Authorization": f"Bearer {os.environ['AIBW_API_KEY']}"},
    json={
        "docType": "cold_email",
        "inputs": {
            "senderName": "Tom Baker",
            "senderCompany": "Northwind Analytics",
            "recipientCompany": "ACME",
            "offer": "A two-week SEO audit with a prioritized fix list"
        }
    },
    timeout=120,
)
body = response.json()
if not response.ok:
    raise RuntimeError(f"{body['error']['code']}: {body['error']['message']}")
print(body["document"]["text"])

The answer is {"document": {"id", "title", "docType", "status", "text", …}} with status 201; text is the document in Markdown. Add templateId to start from a template (its defaults fill the inputs you leave out) and brandVoiceId to write in a brand voice. A cold email also comes split for an email draft: email.subject, email.body and email.bodyHtml (the first email), and email.followUps if follow-ups were requested.

Document types: cold_email, proposal, contract, pitch_deck, case_study, rfp_response, legal_document. The inputs of each type are in the OpenAPI specification, the same fields as the forms in the app, and at GET /api/v1/doc-types.

3. Or write in the background

Tools that cannot wait a minute for an answer (Zapier, Make, serverless functions) can add "callbackUrl": "https://…" to the request. The answer comes at once with status 202 and the new document's id (status generating). When the document is ready we POST {"type": "document.ready", "document": {…}} to that URL, or {"type": "document.failed", "documentId", "error"} if writing failed. The URL must be a public https address; answer 2xx within 10 seconds, otherwise we try twice more. Refusals such as the plan's monthly limit still come back right away as errors. Callbacks are not signed: use a URL nobody can guess, one per request.

Endpoints

  • POST /api/v1/documents: write a new document.
  • GET /api/v1/documents: list documents (page, pageSize up to 100, q for words in the title, docType; sort=created for the newest documents first, include=text for full documents with their text).
  • GET /api/v1/documents/{id}: one document with its current text, including your edits in the app.
  • GET /api/v1/templates: system templates and your own (docType to filter).
  • GET /api/v1/brand-voices: your brand voices.
  • GET /api/v1/doc-types: document types and the inputs each one takes.
  • GET /api/v1/me: the workspace and key of the request (to test a key).

Limits

Per key: 60 requests a minute, and 10 new documents a minute or 100 an hour. Documents also count toward your plan's monthly limit, the same as in the app.

Errors

Every error has the same shape: {"error": {"code": "…", "message": "…"}}, with a matching HTTP status.

StatusCodeMeaning
400invalid_requestThe JSON or a parameter is wrong.
400invalid_inputInputs are missing or too long; `fields` says which.
401unauthorized / invalid_api_keyNo key, or the key is wrong or revoked.
402plan_limit / plan_inactiveNo documents left this month, or the plan ended.
403not_in_planThe plan does not include the API or this document type.
404not_foundNo such document, template or brand voice in your workspace.
429rate_limited / daily_capToo many requests; wait the Retry-After seconds.
500internal_errorSomething failed on our side; try again.
503unavailableThe writing model is busy or down; try again in a minute.

Webhooks

Add an endpoint in Settings → API → Webhooks. When a new document is written, in the app or through the API, we POST a document.created event to it: {"id", "type", "createdAt", "data": {"document": {…}}}. Private drafts are not sent. Answer with a 2xx status within 10 seconds; otherwise we try twice more. The event id stays the same, so you can skip repeats.

Check that an event comes from us: the X-Webhook-Signature header is t=<unix seconds>,v1=<signature>, where the signature is HMAC-SHA256 of <t>.<raw body> with the endpoint's signing secret.

import { createHmac, timingSafeEqual } from "node:crypto";

// rawBody: the request body exactly as received (a string, not parsed JSON).
export function isValidWebhook(rawBody, signatureHeader, secret) {
  const parts = Object.fromEntries(signatureHeader.split(",").map((p) => p.split("=")));
  const age = Math.abs(Date.now() / 1000 - Number(parts.t));
  if (!(age <= 300)) return false; // older than 5 minutes: a replay
  const expected = createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest();
  const given = Buffer.from(parts.v1 ?? "", "hex");
  return given.length === expected.length && timingSafeEqual(given, expected);
}
import hashlib
import hmac
import time

def is_valid_webhook(raw_body: bytes, signature_header: str, secret: str) -> bool:
    parts = dict(p.split("=", 1) for p in signature_header.split(","))
    if abs(time.time() - int(parts.get("t", "0"))) > 300:
        return False  # older than 5 minutes: a replay
    signed = parts["t"].encode() + b"." + raw_body
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))

Zapier

Our Zapier app connects Singleask to thousands of apps without code. Actions: Write Cold Email, Write Proposal and Write Document; trigger: New Document. For example: a new row in Google Sheets → Write Cold Email → a Gmail draft with the subject and body, ready for you to review and send. Connect it with an API key from Settings → API. The app is in private beta: ask us for an invite.

Questions? Write to us; we answer within 24 hours.