Skip to Content

Get gateway configuration

client.gateway.providerConfiguration() gives another library what it needs to send requests through the Modem gateway: the base URL, the customer’s authentication headers, and the Client SDK’s fetch. It establishes the customer’s session first if needed. productId and provider are required, and modelIdentifier is optional.

Create an authenticated configuration

import { ExternalServiceProvider } from '@preternatural-js/client-sdk' const gateway = await client.gateway.providerConfiguration({ provider: ExternalServiceProvider.openai, modelIdentifier: 'gpt-4o-mini', productId: 'your-product-id' })

The result has this shape:

type ProviderGatewayConfiguration = { baseURL: string headers: Record<string, string> fetchImpl: FetchLike }

FetchLike, the type of a fetch function, is exported by the SDK.

The baseURL depends on the provider. For OpenAI, it ends in /v1, and the OpenAI SDK appends /chat/completions. For Anthropic, it has no final /v1, and the Anthropic SDK appends /v1/messages. Pass baseURL to either SDK unchanged.

Get the public gateway configuration

client.gateway.configuration() returns the base URL, the transport’s default headers, and the fetch implementation, without customer headers. Use it for the gateway’s public routes.

Check that the gateway is reachable

The gateway’s root URL needs no authentication:

curl https://gateway.preternatural.ai/
{"ok":true,"service":"gateway"}

Use the configuration safely

Treat headers as customer credentials. Do not print or persist the entire configuration. Pass fetchImpl as well as the URL and headers so the client retains session-aware authentication behavior.

A direct browser OpenAI client needs dangerouslyAllowBrowser: true; the Modem helper already supplies it. This permits customer-token requests and does not justify placing a provider API key in the browser. See OpenAI.

For health versus readiness, see Gateway operations. For supported paths, modalities and header forwarding, see Gateway APIs.

The configuration is a snapshot for an external client, not the observed client returned by client.chat.createProviderClient(). Give the external SDK your own abort signal, cancel its work on account changes, and rebuild its configuration for the next customer. Do not assume that passing a fetch function makes an arbitrary third-party stream participate in all Client SDK session-change notifications.

API reference