Skip to main content

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

Requirements
  • Node.js 18 or later, or Bun. The package is ESM-only ("type": "module"), so use import, not require.
  • Types ship in the package. The StdioConnection type references Node’s stream types, so TypeScript projects may need @types/node installed or "skipLibCheck": true in tsconfig.json.
  • An Igris API key.

Initialize

Never commit your API key to source control. Read it from an environment variable.

Get your API key

  1. Log in to the Igris Dashboard.
  2. Go to Settings → API Keys. This tab only shows for roles that can manage API keys.
  3. Click Generate API Key.
  4. 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.
You add the Authorization header yourself:
It returns 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 }.
See Tool Calls for more.
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 pass traceId, 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): one X-Igris-Metadata header holding the object as JSON. Values can be strings, numbers, or booleans.
  • LLM (connectLlm, the adapters): one X-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.
Reference metadata in policy conditions as 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’s conditions 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.
User-based policies are advisory, not security boundaries. Any holder of an API key can set any X-Igris-User value. The API key is the trust anchor.

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.
With stream: true it returns an async iterable of ChatCompletionChunk:
These methods do not take 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.
See LLM Gateway.

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>.
If you don’t use the adapter, set the Anthropic client’s baseURL to <gateway>/llm/<slug> and send your Igris key as a Bearer token (authToken).

Google

Google’s SDK has no base URL override, so this adapter does not patch a client. It returns the same LlmConnection as connectLlm (base URL <gateway>/llm/<slug>/v1). The client argument is unused, so you can pass null.
To call Google models, use 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, or passthrough.
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 of IgrisError. 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.
Client-side problems throw IgrisError or a plain Error with no status: an unprefixed model, an empty API key, or a failed connectStdio.

Retries and timeouts

  • chat.completions.create and embeddings.create retry 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 fetch with 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.