OriginChain docs
reference · sdks

SDKs

Three first-party clients: Python, TypeScript, and Go. They all wrap the same HTTP API and handle auth, idempotency keys, and retries on transient failures for you. Pick whichever fits your stack.

For raw HTTP usage, see HTTP API reference. For the command line, see CLI (oc).

1. Install.

package manager
# cURL is built into macOS and most Linux distros.
curl --version

2. Connect.

Three environment variables: endpoint URL, bearer token, tenant ID. Save them once per shell session.

create your client
# cURL has no client - every call carries the bearer header.
export OC_HOST=acme.ap-south-1.db.originchain.ai
export OC_TENANT=acme
export OC_TOKEN=oc_live_xxxxxxxxxxxxxxxx

curl -s -o /dev/null -w "HTTP %{http_code}\n" \
  "https://$OC_HOST/health" \
  -H "Authorization: Bearer $OC_TOKEN"
# → HTTP 200 if everything is wired up.

The Python SDK also has OriginChain.from_env() which reads OC_BASE_URL, OC_BEARER, OC_TENANT directly.

3. The surface.

The same operations are exposed in every SDK; only the spelling differs. Below is the most-common subset - schemas, rows, SQL, vector, full-text, graph, and natural language.

the most-common methods
# Schemas
db.schemas.list()
db.schemas.get("shop.orders")
db.schemas.register(open("orders.toml").read())

# Rows  (single + bulk)
db.rows.put("shop.orders", { "id": "o-1", "status": "paid" })
db.rows.get("shop.orders", "o-1")
db.rows.put_batch("shop.orders", rows_iterable, chunk=1000)

# SQL
result = db.sql("SELECT * FROM shop.orders WHERE status = 'paid' LIMIT 10")

# Vector
db.vector.put("shop.products", "sku-1", embedding_768d)
hits = db.vector_topk("shop.products", query=q768, k=10, dim=768)

# Full-text
db.fts.index("shop.products", "description", doc_id="sku-1", text="...")
hits = db.fts.search("shop.products", "description", q="...", mode="bm25", k=10)

# Graph
neighbors = db.graph.neighbors("shop.orders", rel="customer", pk="c-1")

# Natural language
result = db.ask("top 5 customers by revenue", schemas=["shop.orders"])

4. What each SDK covers today.

Python is the most complete client. TypeScript and Go cover SQL, vector, full-text, graph, and ask - row reads and writes go through raw fetch / net/http until the helpers ship in the next release.

Operation Python TypeScript Go
Register schema yes yes use http
Row reads + writes yes use fetch use http
Bulk row writes yes use fetch use http
SQL yes yes yes
Vector put / topk yes yes yes
Full-text index / search yes yes yes
Graph algorithms yes yes yes
Natural language (ask) yes yes yes
Async client AsyncOriginChain native native

5. Error handling.

Each SDK raises typed errors so you can switch on the failure mode rather than parsing strings. See Error reference for the complete code catalog.

catching API errors
from originchain import (
    OCAuthError,            # 401, 403
    OCValidationError,      # 400
    OCNotFoundError,        # 404
    OCRateLimitedError,     # 429 (also exposes .retry_after)
    OCServerError,          # 5xx
)

try:
    db.rows.put("shop.orders", { "id": "o-1", "amount_cents": "not-a-number" })
except OCValidationError as e:
    print(e.status, e.body)

6. Retries + idempotency.

Every SDK attaches a fresh Idempotency-Key header to every mutating call (POST / PUT / PATCH / DELETE). If a network blip causes a retry, the server returns the original result without re-applying the write.

The retry policy is the same in every SDK: 429 honours Retry-After; 500/502/503/504 use exponential backoff (0.25s, 0.5s, 1s, 2s, capped at 4s) up to 3 retries by default.

when to set your own key

For cross-process retries (e.g., a queue worker re-attempting a job after a crash), generate a stable idempotency key from the job's ID and pass it explicitly. The default fresh-per-call UUID only protects retries within one HTTP request lifecycle.