SDKs and client libraries
Call the API from any language: there is no published SDK yet, so use fetch or requests, or generate a typed client from the OpenAPI 3.1 document.
PromptGale has no published SDK package yet. The API is plain JSON over HTTPS, so any HTTP client works, and the OpenAPI 3.1 document at /v1/openapi.json can generate a typed client in most languages.
Call the API with fetch (TypeScript)
A small client you can paste into a project. It sends the key, unwraps the { success, data } envelope and throws the error code on failure.
const API = 'https://promptgale.com';
export class PromptGaleError extends Error {
constructor(public status: number, public code: string, message: string, public requestId?: string) {
super(`${code}: ${message}`);
}
}
export async function promptgale<T>(method: string, path: string, body?: unknown, headers: Record<string, string> = {}): Promise<T> {
const res = await fetch(`${API}${path}`, {
method,
headers: { Authorization: `Bearer ${process.env.PROMPTGALE_API_KEY}`, 'Content-Type': 'application/json', ...headers },
body: body === undefined ? undefined : JSON.stringify(body),
});
const json = await res.json();
if (!json.success) throw new PromptGaleError(res.status, json.error.code, json.error.message, json.error.requestId);
return json.data as T;
}
// One answer, waiting for it (up to 290 seconds).
const task = await promptgale<{ id: string; status: string; result: { text: string } | null }>('POST', '/v1/sync/task', {
taskType: 'CHATGPT',
payload: { prompt: 'best crm for a small agency', country: 'US' },
});
console.log(task.status, task.result?.text.slice(0, 200));Call the API with requests (Python)
import os
import requests
API = "https://promptgale.com"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['PROMPTGALE_API_KEY']}"
class PromptGaleError(Exception):
pass
def promptgale(method, path, **kwargs):
res = session.request(method, API + path, timeout=300, **kwargs)
body = res.json()
if not body["success"]:
err = body["error"]
raise PromptGaleError(f"{err['code']}: {err['message']} (request {err.get('requestId')})")
return body["data"]
task = promptgale("POST", "/v1/sync/task", json={"taskType": "CHATGPT", "payload": {"prompt": "best crm for a small agency", "country": "US"}})
print(task["status"], (task["result"] or {}).get("text", "")[:200])Generate a typed client from OpenAPI
Point a generator at the OpenAPI document. Two common choices:
# TypeScript types for fetch-based code
npx openapi-typescript https://promptgale.com/v1/openapi.json -o promptgale.d.ts
# A full client in Python, Go, Java, C# and other languages
npx @openapitools/openapi-generator-cli generate -i https://promptgale.com/v1/openapi.json -g python -o promptgale-clientThe document names only the engines available now, so regenerate it when Engines changes.
What a client should handle
- Retries: retry
429(RATE_LIMITED,QUEUE_LIMIT_EXCEEDED) and503(ENGINE_UNAVAILABLE) after theRetry-Afterheader. See Errors. - Idempotency: send an
Idempotency-Keyheader on every create, so a retried request never runs the same task twice. See Tasks. - Timeouts:
POST /v1/sync/taskcan hold the request for up to 290 seconds; set the client timeout above that, or sendPrefer: wait=N. - Pagination: lists answer
{ items, nextCursor, hasMore }; passnextCursorback ascursor.
From an agent instead of code
Agents (Claude Code, Cursor, Codex and others) can use PromptGale without any client code, through the MCP server: see Connect an agent.
Last updated