Igris SDK
The Igris SDK (@igris-security/sdk) is a TypeScript client for the Igris gateway. It builds MCP connection configs, calls MCP tools, sends LLM requests through the gateway, patches OpenAI and Anthropic clients to use it, and manages connections, policies, and audit events.
Installation
- Node.js 18 or later, or Bun. The package is ESM-only (
"type": "module"), so useimport, notrequire. - Types ship in the package. The
StdioConnectiontype references Node’s stream types, so TypeScript projects may need@types/nodeinstalled or"skipLibCheck": trueintsconfig.json. - An Igris API key.
Initialize
Get your API key
- Log in to the Igris Dashboard.
- Go to Settings → API Keys. This tab only shows for roles that can manage API keys.
- Click Generate API Key.
- Copy the key. It is shown only once.
MCP gateway
igris.connectHttp(slug, options?)
Builds the connection config for an HTTP MCP connection. It makes no network call.
Authorization header yourself:
HttpConnection:
igris.mcp
Calls MCP tools through the gateway without an MCP client. All three methods take the connection slug and optional { user, traceId, metadata }.
igris.connectStdio() exists for backward compatibility only. Stdio MCP connections are disabled, so it fails at runtime.Identity and metadata
Pass user identity and metadata with MCP and LLM requests. Igris uses them for policy conditions, audit trails, and trace correlation. All fields are optional.Trace IDs
If you don’t passtraceId, the SDK generates one: ig_trace_ followed by 16 hex characters. Each connectHttp(), connectLlm(), or withIgris() call gets its own ID. Pass the same traceId to group calls:
Metadata
How the SDK sends metadata depends on the gateway:- MCP (
connectHttp,igris.mcp): oneX-Igris-Metadataheader holding the object as JSON. Values can be strings, numbers, or booleans. - LLM (
connectLlm, the adapters): oneX-Igris-Metadata-<key>header per key. Only string values are sent; others are skipped. The gateway lowercases header names, so the key reaches policies in lowercase.
metadata.<key>. Use lowercase keys and string values so conditions match on both gateways.
The gateway ignores the whole X-Igris-Metadata JSON header (it does not reject the request) if any of these is true:
Policies see no metadata in that case. Per-key
X-Igris-Metadata-<key> headers are not subject to these checks.
Conditions
A rule’sconditions can match on user (the X-Igris-User value) or metadata.<key>. Any other field is rejected with 422 when you create or change the rule.
If a condition references a field the request doesn’t carry, the rule is skipped, not denied. See Policies.
LLM gateway
igris.chat.completions.create(request)
The model must be @slug/model. The slug picks the connection and the rest is sent to the provider. A model without the prefix throws IgrisError before any request.
stream: true it returns an async iterable of ChatCompletionChunk:
user, traceId, or metadata. To send them, use connectLlm or an adapter.
igris.embeddings.create(request)
igris.llmProviders.list()
Returns LlmProviderInfo[] (slug, name, baseUrl, authStyle, supportedEndpoints).
igris.connectLlm(slug, options?)
Builds an LlmConnection for any OpenAI-compatible client. options is { user?, traceId?, metadata? } where metadata values are strings.
Adapters
Adapters patch an existing provider client so its calls go through Igris. They change the client in place and return it. Import them from@igris-security/sdk/adapters/openai, .../anthropic, or .../google. Each takes (client, igris, connectionSlug, options?), where options is { user?, traceId?, metadata? }. One trace ID is generated per withIgris call and reused for every request from that client.
Use the provider’s real model name with adapters (gpt-4o), not the @slug/ form.
OpenAI
Sets the client’s base URL to<gateway>/llm/<slug>/v1.
Anthropic
Sets the client’s base URL to<gateway>/llm/<slug> (no /v1, because the Anthropic SDK adds it) and authenticates with Authorization: Bearer <Igris key>.
baseURL to <gateway>/llm/<slug> and send your Igris key as a Bearer token (authToken).
LlmConnection as connectLlm (base URL <gateway>/llm/<slug>/v1). The client argument is unused, so you can pass null.
igris.chat.completions.create({ model: "@google-prod/gemini-2.0-flash", ... }).
Management API
These resources call the REST API under/api/v1. They need an API key with the matching permissions. See Permissions.
Pagination
Every list method returns{ data, meta }:
connections.list and policies.list take limit and offset. auditEvents.list also takes cursor. llmProviders.list() returns a plain array.
igris.connections
serverType is "http" or "llm". authType is "none", "bearer", "header", or "api_key". bearer needs a credential. header needs one too (except for keyless self-hosted LLM providers) and sends it in authHeaderName (default Authorization). api_key is for LLM connections only and needs a credential and authConfig. The API rejects oauth, mtls, azure, aws, and gcp with 400. See Connections.
igris.policies
A policy applies to the connections in
connectionSlugs. null or omitted on create means org-wide. connectionSlug (singular) on input is deprecated and is sent as [slug]. In list, connectionSlug filters to one connection, and "__org__" returns org-wide policies only.
Each rule has a target:
{ kind: "mcp_tool", tool: "delete_*" }matches MCP tool names (*wildcards).{ kind: "llm_model", model: string }matches an LLM model.{ kind: "llm_endpoint", endpoint }matches an endpoint:chat.completions,embeddings,images.generate,audio.transcriptions,audio.speech, orpassthrough.
action is allow, deny, alert, or redact. A limit ({ requests?, tokens?, dollars?, per: "minute" | "hour" | "day" }) is allowed on LLM rules only. On an MCP tool rule the API returns 422.
igris.auditEvents
Events are newest first. To page with a cursor, pass
meta.nextCursor as cursor. nextCursor is set only when the page is full; it is null on the last page, so stop when it is null.
Errors
Failed HTTP responses throw a subclass ofIgrisError. err.status is the HTTP status and err.response is the parsed JSON body. If the body isn’t JSON, it is { error: "<body text>" }.
A 403 from the management API (
connections, policies, auditEvents, llmProviders) means your key lacks the permission or your plan doesn’t allow the action. It throws a plain IgrisError, not IgrisPolicyDeniedError. A 403 from chat.completions, embeddings, or mcp throws IgrisPolicyDeniedError.MCP policy denials come back as HTTP 200 with a JSON-RPC error. igris.mcp turns them into IgrisPolicyDeniedError. Other JSON-RPC errors throw IgrisError with no status.IgrisError or a plain Error with no status: an unprefixed model, an empty API key, or a failed connectStdio.
Retries and timeouts
chat.completions.createandembeddings.createretry once on a network-level error. They don’t retry error responses (including 5xx), so retry those yourself if you want to. They time out after 120 seconds. The timeout is not configurable.- All other methods use a plain
fetchwith no retry and no timeout.
Environment variables
Tool Calls
Call MCP tools programmatically with
igris.mcp.Connections
Create and manage encrypted credential vaults.
MCP Client Config
Generate configs for Claude Desktop, Cursor, and more.
API Reference
REST API endpoints for all Igris resources.