SDKs & integrations
Python & JavaScript
The API is plain JSON over HTTPS, so any HTTP client works. There are no official SDK packages yet Not yet. Until there are, copy one of these small helpers into your project. Each is a single file, has no dependency beyond requests (Python) or built-in fetch (Node 18+), and is tested against the API.
Python
"""Minimal Obscate helper: copy this file into your project. pip install requests"""
import os
import requests
class Obscate:
def __init__(self, api_key=None, base_url=None, timeout=30):
self.base = (base_url or os.environ.get("OBSCATE_BASE_URL", "https://api.obscate.com")).rstrip("/")
self.s = requests.Session()
self.s.headers["x-api-key"] = api_key or os.environ["OBSCATE_API_KEY"]
self.timeout = timeout
def _post(self, path, body):
r = self.s.post(self.base + path, json=body, timeout=self.timeout)
if r.status_code >= 400: # error bodies never contain your input
raise RuntimeError(f"Obscate {path}: HTTP {r.status_code} {r.json().get('detail')}")
return r.json()
def redact(self, text, strategy="fpe", **kw):
return self._post("/v1/redact", {"text": text, "strategy": strategy, **kw})
def restore(self, text, redaction):
"""Undo a redact() result: fpe needs only the key; tokenize/synthetic use its token_map."""
if redaction["strategy"] == "fpe":
return self._post("/v1/restore-fpe", {"text": text})["text"]
return self._post("/v1/restore", {"text": text, "token_map": redaction["token_map"]})["text"]
def redact_json(self, payload, strategy="fpe", **kw):
return self._post("/v1/redact-json", {"json": payload, "strategy": strategy, **kw})
def restore_json(self, payload, redaction):
return self._post("/v1/restore-json", {
"json": payload, "fpe": redaction["strategy"] == "fpe", "token_map": redaction["token_map"],
"type_changes": redaction["type_changes"], "keys_redacted": redaction["keys_redacted"]})["json"]
if __name__ == "__main__":
ob = Obscate()
for strategy in ("fpe", "tokenize"):
red = ob.redact("Please refund card 4242 4242 4242 4242 and reply to priya.sharma@example.com", strategy)
print(strategy, "->", red["redacted"])
assert ob.restore(red["redacted"], red) == "Please refund card 4242 4242 4242 4242 and reply to priya.sharma@example.com"
rj = ob.redact_json({"name": "Priya Sharma", "qty": 3})
assert ob.restore_json(rj["redacted"], rj) == {"name": "Priya Sharma", "qty": 3}
print("ok")
from obscate_helper import Obscate
ob = Obscate() # reads OBSCATE_API_KEY (and OBSCATE_BASE_URL)
red = ob.redact("Refund card 4242 4242 4242 4242")
reply = call_your_llm(red["redacted"]) # the model sees tokens only
print(ob.restore(reply, red))
JavaScript / TypeScript
// Minimal Obscate helper for Node 18+ / Deno / Bun / edge runtimes. Copy into your project.
// Server-side only: never ship your API key to a browser.
export function obscate({
apiKey = process.env.OBSCATE_API_KEY,
baseUrl = process.env.OBSCATE_BASE_URL ?? "https://api.obscate.com",
} = {}) {
const post = async (path, body) => {
const res = await fetch(baseUrl + path, {
method: "POST",
headers: { "x-api-key": apiKey, "content-type": "application/json" },
body: JSON.stringify(body),
});
const data = await res.json();
if (!res.ok) throw new Error(`Obscate ${path}: HTTP ${res.status} ${JSON.stringify(data.detail)}`);
return data;
};
return {
redact: (text, strategy = "fpe", opts = {}) => post("/v1/redact", { text, strategy, ...opts }),
restore: async (text, r) =>
r.strategy === "fpe"
? (await post("/v1/restore-fpe", { text })).text
: (await post("/v1/restore", { text, token_map: r.token_map })).text,
redactJson: (json, strategy = "fpe", opts = {}) => post("/v1/redact-json", { json, strategy, ...opts }),
restoreJson: async (json, r) =>
(await post("/v1/restore-json", {
json, fpe: r.strategy === "fpe", token_map: r.token_map,
type_changes: r.type_changes, keys_redacted: r.keys_redacted,
})).json,
};
}
// Demo: node obscate_helper.mjs
if (import.meta.url === `file://${process.argv[1]}`) {
const ob = obscate();
const text = "Please refund card 4242 4242 4242 4242 and reply to priya.sharma@example.com";
for (const strategy of ["fpe", "tokenize"]) {
const r = await ob.redact(text, strategy);
console.log(strategy, "->", r.redacted);
if ((await ob.restore(r.redacted, r)) !== text) throw new Error("round trip failed");
}
const rj = await ob.redactJson({ name: "Priya Sharma", qty: 3 });
const back = await ob.restoreJson(rj.redacted, rj);
if (back.name !== "Priya Sharma" || back.qty !== 3) throw new Error("json round trip failed");
console.log("ok");
}
import { obscate } from "./obscate_helper.mjs";
const ob = obscate();
const red = await ob.redact("Refund card 4242 4242 4242 4242");
const reply = await callYourLLM(red.redacted); // the model sees tokens only
console.log(await ob.restore(reply, red));
Server-side only. Never put your API key in browser JavaScript; anyone could read it. Call Obscate from your backend, a serverless function or an edge worker.
Notes
- Both helpers default to
fpe(map-free) like the integrations; pass"tokenize"or"synthetic"to use a token map. Theredactresult holds the map in memory; don’t log it. - Retry on
429afterretry-afterseconds and on503. See errors. - Integrations for agent frameworks: MCP server, LangChain, LlamaIndex.