# createSearch

Configure one normalized search client with explicit providers and time budgets.

Canonical: https://searchsdk.dev/docs/api/create-search
Markdown: https://searchsdk.dev/docs/api/create-search.md

<a id="signature"></a>

## Signature

> **TypeScript reference**
> The API names, code and policy behavior in this article describe the TypeScript SDK. See [your language guide](https://searchsdk.dev/docs/sdks) for its supported surface and limits.

**TypeScript**

```typescript
import { createSearch } from '@belweave/search-sdk';
import type { SearchConfig } from '@belweave/search-sdk';

// createSearch(config: SearchConfig)
// → { web: { search(request, options?), searchBatch(requests, options?) } }
```

<a id="configuration"></a>

## Configuration

| Field | Behavior |
| --- | --- |
| `provider` | Required SearchProvider; first attempted provider. |
| `fallback` | Optional ordered array of distinct provider IDs. |
| `timeoutMs` | Total deadline in integer milliseconds; default 10,000. |
| `attemptTimeoutMs` | Per-attempt budget; defaults to the total configured budget. |
| `retry` | Optional additional attempts per provider with bounded backoff; off by default. |
| `maxConcurrency` | Optional active-operation bound; queue time shares the deadline. |
| `cache` | Optional `{ ttlMs, maxEntries? }` local successful-response cache. |
| `deduplicate` | Optional sharing of identical in-flight requests; false by default. |

Both durations must be between 1 and 2,147,483,647. Unknown configuration fields, duplicate provider IDs, invalid capability descriptors, and invalid budgets are configuration errors. Factory configuration errors can throw synchronously.

<a id="example"></a>

## Example

**client.ts · server**

```typescript
import { createSearch } from '@belweave/search-sdk';
import { context } from '@belweave/search-sdk/context';
import { tinyfish } from '@belweave/search-sdk/tinyfish';

const contextKey = process.env.CONTEXT_API_KEY;
const tinyfishKey = process.env.TINYFISH_API_KEY;
if (!contextKey || !tinyfishKey) throw new Error('Missing server credentials');

const client = createSearch({
  provider: context({ apiKey: contextKey }),
  fallback: [tinyfish({ apiKey: tinyfishKey })],
  timeoutMs: 10_000,
  attemptTimeoutMs: 4_000,
});

const response = await client.web.search({ query: 'SQLite write concurrency' });
console.log(response.provider, response.attempts, response.warnings);
```

Set a smaller per-attempt budget when you need to reserve time for fallback. A total deadline never extends to accommodate another provider.
