Skip to main content

Client

Create a client​

import { SourcingClient } from '@search-engine-sdk/core';

const client = new SourcingClient({
baseUrl: '/api/v2',
});

baseUrl is required. A trailing slash is removed. In the browser, same-origin requests send the host's cookies (credentials defaults to same-origin). For a Node.js client, use an absolute URL.

Pick one credential:

SessionOption
HttpOnly cookie on the host originOmit both token options. Call client.auth.me() to read the signed-in user.
Keycloak access tokenbearerToken is sent as Authorization: Bearer …. Pass a string or a function that returns the current token. Return nothing when the cookie is enough.
Server-side API keyapiKey is sent as X-API-Key. Keep the key on the server.

Setting both apiKey and bearerToken throws when the client is constructed. A request that would send both headers throws before fetch. auth.login and auth.logout strip those headers and use the cookie.

const client = new SourcingClient({
baseUrl: '/api/v2',
bearerToken: () => accessToken(),
headers: () => ({ 'X-Tenant-Id': tenantId }), // any extra header the host needs
});

headers may be a static set or a function called on every request. A header on that one call replaces the same name. candidates.prepare always sets X-Session-ID to the chat id.

Matching​

MatchingClient is that same client for a matching server. Pass tenant and the client sends it as X-Tenant-Id. A value already present in headers, or on that one call, is left as given. An empty tenant omits the header.

import { MatchingClient } from '@search-engine-sdk/core';

const client = new MatchingClient({
baseUrl: '/api/v2',
tenant: () => currentTenantId(),
});

const tenants = await client.tenants();

tenants() reads GET /tenants. A 404, a server without a tenant list, returns null. A matching server with no rows returns [].

features() reads GET /features once and reuses the result. A failed read is not cached. The payload reports outline, engines, agent, and evaluate.

If a proxy sits in front of the API, point baseUrl at that route and forward server-sent events without buffering them. Keep the signed-in user on the upstream request so saved conversations stay scoped to that user.