Skip to article

Provider-native transport

Use fixed-origin operations with typed inputs, bounded responses, explicit retries, and sanitized metadata.

On this page

Start with a provider client

Provider client factories bind supported operations to fixed origins and authentication. Use their typed methods for actual provider work. createNativeTransport is the lower-level primitive used by those clients; it does not discover endpoints or validate provider JSON schemas.

native-search.ts · server
import { createContextClient } from '@belweave/search-sdk/native-context';

const apiKey = process.env.CONTEXT_API_KEY;
if (!apiKey) throw new Error('CONTEXT_API_KEY is required');

const client = createContextClient({ apiKey, maxConcurrency: 4 });
const response = await client.search({
  body: { query: 'SQLite write concurrency', numResults: 10 },
  timeoutMs: 8_000,
});
console.log(response.data.results);
console.log(response.metadata.status, response.metadata.attempts);

Operation and input

Operation descriptorBehavior
idStatic operation name; never put user input or secrets in it.
methodGET, POST, PUT, PATCH, DELETE, or HEAD.
pathRelative to the fixed base path; {name} placeholders use input.path.
retryableExplicit replay eligibility. Defaults false, even for GET.
responsejson by default; text, bytes, raw, or sse.
Request inputBehavior
pathPlaceholder values encoded as single path segments; do not pre-encode IDs.
queryScalar values or repeated arrays; null and undefined omitted.
bodyJSON serialized; cannot coexist with rawBody.
rawBodyFetch BodyInit, including FormData. Streaming request bodies are unsupported.
headersNon-auth endpoint headers; configured headers cannot be overridden.
signal, timeoutMsCancellation and complete-operation deadline.

Data and metadata

TypeScript · shape
interface NativeResponse<T> {
  data: T;
  metadata: {
    provider: string;
    operation: string;
    status: number;
    requestId?: string;
    attempts: readonly {
      attempt: number;
      durationMs: number;
      outcome: 'success' | 'error';
      status?: number;
      code?: string;
    }[];
  };
}

Metadata omits URLs, queries, request input, credentials, provider error bodies, and arbitrary headers. Successful data is native provider data and may itself contain sensitive fields. Generic response types are compile-time assertions, not runtime provider schema checks.

Limits and credentials

SettingDefault / boundary
timeoutMs10,000 ms, including queue, backoff, fetch, response parsing, and stream lifetime.
maxConcurrency8 per transport instance; 1–1,024 when configured. Queue shares the deadline.
maxResponseBytes10 MiB of decoded response bytes, including streaming data.
retry.maxRetries0; retries require both opt-in policy and operation eligibility.

The base URL must be HTTPS and has no credentials, query, or fragment. Operation input cannot change origin or replace configured authentication. Raw responses are buffered under the size cap. Let Fetch set the multipart boundary for FormData.

The response cap is not a process-memory limit: decoded strings and parsed objects require additional memory. Uploads are materialized before dispatch and do not have an SDK upload-size cap; bound them in your application.

Response modes

ModeReturned data
jsonParsed native JSON. Empty 204/205 or HEAD becomes null.
textDecoded text.
bytesUint8Array.
rawA buffered, bounded Response.
sseAsyncIterable<NativeSSEEvent>; incremental and single-consumer.