---
title: '@runic-labs/sdk'
description: askRunic et storeResult — l’intégralité du contrat destiné aux agents.
sidebar:
  order: 3
---
`@runic-labs/sdk` est le seul package que la plupart des intégrations doivent importer directement. Il encapsule `@runic-labs/cache` et `@runic-labs/ledger` derrière deux fonctions.

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

## Fonctions au niveau du module

Pour le cas courant — un processus d’agent, un stockage par défaut basé sur des fichiers — utilisez directement les fonctions libres :

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

### `askRunic(decision)`

Vérifie si cette décision exacte a déjà été résolue.

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

Renvoie `Promise<CachedEntry | null>` — `null` en cas d’absence, ou l’entrée mise en cache (et consigne un succès dans le registre) en cas de correspondance.

| 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)`

Enregistre un artefact fraîchement généré pour une décision et consigne son coût afin qu’une future correspondance sache combien elle a économisé.

| 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. |

Renvoie `Promise<void>`.

## `createRunicClient(options?)`

Utilisez ceci à la place des fonctions au niveau du module lorsque vous avez besoin de plusieurs clients indépendants — le plus souvent pour les tests, ou lorsque vous choisissez explicitement un stockage en mémoire :

```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. |

Renvoie un `RunicClient` ayant la même forme `askRunic` / `storeResult` que les fonctions au niveau du module, limité aux instances `cache`/`ledger` que vous avez fournies.

## Suite

- [Cache](/cache) — créez des implémentations `CacheStore` personnalisées
- [Ledger](/ledger) — lisez directement les résumés du registre
- [CLI](/cli) — inspectez l’état depuis la ligne de commande
