> ## Documentation Index
> Fetch the complete documentation index at: https://docs.withfoundry.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK reference

> Method signatures and options for @withfoundry/sdk.

# SDK reference

Package: `@withfoundry/sdk`\
API base: `https://api.withfoundry.ai`\
Auth: API key with prefix `key_` passed as `Authorization: Bearer key_...`

## Client

### `new Foundry(options)`

| Option    | Type   | Required | Description                                                |
| --------- | ------ | -------- | ---------------------------------------------------------- |
| `apiKey`  | string | Yes      | Foundry API key.                                           |
| `baseUrl` | string | No       | Override API base (default: `https://api.withfoundry.ai`). |

```javascript theme={null}
const foundry = new Foundry({ apiKey: 'key_...' });
```

***

## Memory

### `foundry.memory.write(params)`

**Params:** `{ namespace: string, entries: Array<{ content: string, metadata?: object }> }`\
**Returns:** `Promise<{ data: { ids: string[] }, meta }>`

```javascript theme={null}
const { data } = await foundry.memory.write({
  namespace: 'my-app',
  entries: [{ content: 'Text', metadata: { source: 'sdk' } }],
});
// data.ids = ['mem_...']
```

***

### `foundry.memory.search(params)`

**Params:** `{ namespace: string, query: string, limit?: number, metadataFilter?: object }`\
**Returns:** `Promise<{ data: Array<{ id, content, metadata, score? }>, meta }>`

```javascript theme={null}
const { data } = await foundry.memory.search({
  namespace: 'my-app',
  query: 'auth method',
  limit: 5,
});
```

***

### `foundry.memory.getContext(params)`

**Params:** `{ namespace: string, query: string, limit?: number }`\
**Returns:** `Promise<{ data: { text: string, entryIds: string[] }, meta }>`

```javascript theme={null}
const { data } = await foundry.memory.getContext({
  namespace: 'my-app',
  query: 'user preferences',
  limit: 3,
});
// data.text = concatenated context string
```

***

## Security

### `foundry.security.scanRepo(params)`

**Params:** `{ repoUrl: string, branch?: string, waitForCompletion?: boolean }`\
**Returns:** `Promise<{ data: { scanId: string, status: string, findings?: Finding[] }, meta }>`

```javascript theme={null}
const { data } = await foundry.security.scanRepo({
  repoUrl: 'https://github.com/org/repo',
  branch: 'main',
  waitForCompletion: true,
});
// data.scanId, data.status, data.findings (if completed)
```

***

### `foundry.security.getScanResult(scanId)`

**Params:** `scanId: string`\
**Returns:** `Promise<{ data: { scanId, status, findings?, error? }, meta }>`

```javascript theme={null}
const { data } = await foundry.security.getScanResult('scan_abc123');
```

***

## Response envelope

All successful responses follow the API envelope:

```typescript theme={null}
{
  success: true;
  data: T;       // method-specific
  meta: { requestId: string };
}
```

The SDK typically exposes `data` and `meta`; `success` may be omitted if errors are thrown. On HTTP errors (4xx/5xx), the SDK may throw or return an error object—see package docs for exact behavior.

## Finding type (Security)

```typescript theme={null}
interface Finding {
  id: string;
  severity: 'critical' | 'high' | 'medium' | 'low' | 'info';
  title: string;
  description: string;
  file: string;
  line: number;
  suggestion?: string;
}
```
