---
title: "Sdk"
description: askRunic and storeResult — the entire agent-facing contract.
sidebar:
  order: 3
---

`@runic-labs/sdk` is the only package most integrations need to import directly. It wraps `@runic-labs/cache` and `@runic-labs/ledger` behind two functions.

```package-install
npm i @runic-labs/sdk
```

## Module-level functions

For the common case — one agent process, default file-backed storage — use the free functions directly:

```ts
import { askRunic, storeResult } from "@runic-labs/sdk";
```

### `askRunic(decision)`

Checks whether this exact decision has already been resolved.

| Prop | Type | Default | Description |
| - | - | - | - |
| `decision` | `Decision` | - | { intent: string; params: Record<string, unknown> } |

Returns `Promise<CachedEntry | null>` — `null` on a miss, or the cached entry (and logs a hit to the ledger) on a hit.

| Prop | Type | Default | Description |
| - | - | - | - |
| `signature?` | `string` | - | The normalized signature this entry is keyed on. |
| `artifact?` | `unknown` | - | Whatever was passed to storeResult() originally. |
| `tokensSpent?` | `number` | - | What producing this artifact cost the first time. |
| `createdAt?` | `number` | - | Epoch ms when this entry was first stored. |
| `lastUsedAt?` | `number` | - | Epoch ms of the most recent hit. |
| `hitCount?` | `number` | - | Number of times this entry has been reused. |
| `stale?` | `boolean` | - | Advisory only — Runic never acts on this itself. |

### `storeResult(decision, artifact, tokensSpent)`

Records a freshly-generated artifact for a decision, and logs what it cost so a future hit knows how much it saved.

| Prop | Type | Default | Description |
| - | - | - | - |
| `decision` | `Decision` | - | Same shape as askRunic's argument. |
| `artifact` | `unknown` | - | Whatever you want returned on a future cache hit. |
| `tokensSpent` | `number` | - | Agent-reported cost of producing this artifact. Runic never measures this itself. |

Returns `Promise<void>`.

## `createRunicClient(options?)`

Use this instead of the module-level functions when you need multiple independent clients — most commonly for tests, or when explicitly choosing in-memory storage:

```ts
import { createRunicClient } from "@runic-labs/sdk";
import { createCache, MemoryCacheStore } from "@runic-labs/cache";
import { createLedger, MemoryLedgerStore } from "@runic-labs/ledger";

const runic = createRunicClient({
  cache: createCache(new MemoryCacheStore()),
  ledger: createLedger(new MemoryLedgerStore()),
});

await runic.askRunic({ intent: "summarize_pr", params: { repo, pr } });
await runic.storeResult({ intent: "summarize_pr", params: { repo, pr } }, artifact, tokensUsed);
```

| Prop | Type | Default | Description |
| - | - | - | - |
| `cache?` | `Cache` | - | Defaults to a file-backed cache under .runic/ if omitted. |
| `ledger?` | `Ledger` | - | Defaults to a file-backed ledger under .runic/ if omitted. |

Returns a `RunicClient` with the same `askRunic` / `storeResult` shape as the module-level functions, scoped to whatever `cache`/`ledger` instances you passed in.
