Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

index.ts

70 lines1.9 KB

1/**
2 * @modelschemas/client — typed fetch client for the modelschemas service.
3 *
4 * Everything under ./generated is produced by @hey-api/openapi-ts from the
5 * service's own openapi.json (pnpm run generate:client); this file is the
6 * hand-written entry adding pluggable auth and branded model ids.
7 */
8import { createClient, createConfig } from './generated/client/index.js'
9​
10import type { ClientOptions } from './generated/types.gen.js'
11​
12export {
13 getActivitySchemas,
14 getProviderOpenApi,
15 getSchema,
16 getServiceIndex,
17 getStatus,
18 listAllSchemas,
19 listChanges,
20 listProviders,
21 listProviderSchemas,
22 estimateCost,
23 exportCatalog,
24 extractFalPricing,
25 syncProvider,
26 validatePayload,
27} from './generated/index.js'
28export type * from './generated/index.js'
29export { createClient, createConfig }
30export {
31 asListedModelId,
32 getModel,
33 listModels,
34 listProviderModels,
35 type ListedModel,
36 type ListedModelList,
37 type ListedModelId,
38} from './listed-model.js'
39​
40export interface ModelschemasClientOptions {
41 /** Service origin, e.g. https://modelschemas.example.com */
42 baseUrl: string
43 /** API key (POST /v1/agents/register-key) sent as Authorization: Bearer. */
44 apiKey?: string
45 /** Pre-signed agent JWT (agent-auth protocol) — alternative to apiKey. */
46 agentJwt?: string
47 fetch?: typeof globalThis.fetch
49​
50/**
51 * Create a configured client instance to pass to any SDK call via the
52 * `client` option:
53 *
54 * ```ts
55 * const client = createModelschemasClient({ baseUrl, apiKey })
56 * const { data } = await listProviders({ client })
57 * ```
58 */
59export function createModelschemasClient(options: ModelschemasClientOptions) {
60 const credential = options.apiKey ?? options.agentJwt
61 return createClient(
62 createConfig<ClientOptions>({
63 baseUrl: options.baseUrl,
64 fetch: options.fetch,
65 headers: credential
66 ? { Authorization: `Bearer ${credential}` }
67 : undefined,
68 }),
69 )