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
- A workspace administrator or member creates a Safeguard AI key (
sg_sk_..., scopeai:chat). See Create an API key. - Your code installs an SDK and passes the key, or sets
SAFEGUARD_API_KEY. - 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.
| Language | Package | Runtime |
|---|---|---|
| TypeScript and Node.js | @safeguard-sh/sdk | Node 18 or newer, ESM and CommonJS, types included, no dependencies |
| Python | safeguard-sdk (import safeguard_sdk) | Python 3.9 or newer, sync and async, one dependency (httpx) |
| Go | safeguard.sh/sdk | Go 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
- Create an API key: step by step in the web app.
- Install and Quickstart in your language.
- Conversations, Queries and Streaming.
- Errors and retries, Rate and usage limits and Configuration.
- API reference: TypeScript, Python, Go.
- Examples and Versioning and changelog.
Related
- MCP Integrations: connect an AI assistant to the hosted MCP server.
- CLI: scan from a terminal or a CI job.
- Webhooks and Events: signed event deliveries.
- API Platform: OpenAI-compatible model API and its clients.
- Guard SDK: the Guard agents and how to get them.
Slack, Teams & Discord
Route findings and events into your team's Slack workspace, Microsoft Teams tenant, or Discord server - set up credentials, pick a default channel and message the Safeguard bot.
Create an API key
Create a Safeguard AI key with the ai:chat scope in the web app, keep it safe, and revoke it.