Safeguard Docs
Safeguard AI SDKs

Safeguard AI SDKs

Official TypeScript, Python and Go SDKs for Safeguard AI. Send a prompt from your own code, stream the answer, and keep conversations, with a secret key that carries the ai:chat scope.

Safeguard AI SDKs

The Safeguard AI SDKs let you send a prompt to Safeguard AI from your own code and read the answer back: as one reply, as a stream of events, or as a conversation you keep adding to. They are generally available for TypeScript and Node.js, Python and Go, version 0.1.0.

Install only the official package names. The packages are @safeguard-sh/sdk (npm), safeguard-sdk (PyPI index at registry.safeguard.sh) and safeguard.sh/sdk (Go). Install them as shown on Install, from npmjs.com or from registry.safeguard.sh. A package with a similar name from anywhere else is not Safeguard's: do not install it, and tell us at hi@safeguard.sh.

What the SDKs do

The SDKs cover conversations and queries against the Safeguard AI API:

  • Ask a question and get the whole answer, or stream it event by event.
  • Start a conversation, continue it, list your conversations and read back their stored turns.
  • Read what the key can see: its tenant, organization, user and products.

Everything else in Safeguard (scans, SBOMs, vault, policies and Guard) is outside the SDKs. For those, use the MCP server, the CLI or webhooks.

How it fits together

  1. A workspace administrator or member creates a Safeguard AI key (sg_sk_..., scope ai:chat). See Create an API key.
  2. Your code installs an SDK and passes the key, or sets SAFEGUARD_API_KEY.
  3. The SDK calls https://api.safeguard.sh/gpt/v1/ai. The key fixes the tenant, organization and user: there is no organization option in the SDKs, and nothing else identifies you.
LanguagePackageRuntime
TypeScript and Node.js@safeguard-sh/sdkNode 18 or newer, ESM and CommonJS, types included, no dependencies
Pythonsafeguard-sdk (import safeguard_sdk)Python 3.9 or newer, sync and async, one dependency (httpx)
Gosafeguard.sh/sdkGo 1.22 or newer, standard library only

All three share one surface: a Safeguard client, context(), conversations (create, list, get, messages), query() for the full answer, stream() for events, and one typed error with status, code and retryAfter. The SDKs send no telemetry.

Where to go next

On this page