Skip to main content

Interface: ProviderConfig

Defined in: packages/core/src/providers/types.ts:66

Provider configuration (v2 - simplified)

✨ MAJOR SIMPLIFICATION from v1:

  • ❌ Removed: transport, proxyUrl (over-engineered)
  • ✅ Kept: fetch (simple, powerful, standard)

Examples

const config: ProviderConfig = {
// apiKey defaults to OPENAI_API_KEY env var
};
const config: ProviderConfig = {
apiKey: 'sk-...',
baseUrl: 'https://custom-endpoint.com/v1'
};
import { fetch as tauriFetch } from '@tauri-apps/api/http';

const config: ProviderConfig = {
fetch: tauriFetch // Simple!
};
const mockFetch = vi.fn().mockResolvedValue(
new Response(JSON.stringify({ ... }))
);

const config: ProviderConfig = {
fetch: mockFetch
};
import { wrapWithRetries } from '@baleybots/core';

const config: ProviderConfig = {
fetch: wrapWithRetries(globalThis.fetch, 5)
};

Properties

apiKey?

optional apiKey?: string

Defined in: packages/core/src/providers/types.ts:74

API key for the provider

Falls back to environment variable if not provided:

  • OpenAI: OPENAI_API_KEY
  • Anthropic: ANTHROPIC_API_KEY

baseUrl?

optional baseUrl?: string

Defined in: packages/core/src/providers/types.ts:86

Base URL for the provider API

Use this for:

  • Self-hosted endpoints
  • Custom API gateways
  • Development proxies

Defaults to provider's official endpoint


fetch?

optional fetch?: {(input, init?): Promise<Response>; (input, init?): Promise<Response>; }

Defined in: packages/core/src/providers/types.ts:149

Custom fetch implementation

Use this to:

  • Route through Tauri IPC: import { fetch } from '@tauri-apps/api/http'
  • Use React Native networking
  • Mock for testing: vi.fn().mockResolvedValue(new Response(...))
  • Add retry logic: wrapWithRetries(globalThis.fetch, 3)
  • Route through proxy: (url, init) => fetch(proxyUrl, init)
  • Log requests: wrapWithLogging(globalThis.fetch)

Default: globalThis.fetch

Call Signature

(input, init?): Promise<Response>

MDN Reference

Parameters
input

RequestInfo | URL

init?

RequestInit

Returns

Promise<Response>

Call Signature

(input, init?): Promise<Response>

MDN Reference

Parameters
input

string | Request | URL

init?

RequestInit

Returns

Promise<Response>

Examples

import { fetch as tauriFetch } from '@tauri-apps/api/http';
config: { fetch: tauriFetch }
config: {
fetch: async (url, init) => {
// RN-specific handling
return fetch(url, { ...init, credentials: 'include' });
}
}

headers?

optional headers?: Record<string, string>

Defined in: packages/core/src/providers/types.ts:118

Custom headers to include in all requests

Example

headers: {
'X-Custom-Header': 'value',
'X-Request-ID': uuid()
}

proxyUrl?

optional proxyUrl?: string

Defined in: packages/core/src/providers/types.ts:105

Proxy URL for routing requests through a backend proxy server

Use this to avoid CORS errors when making requests from the browser. When set, all requests will be routed through this proxy URL.

Example

import { anthropic } from '@baleybots/core';

const model = anthropic('claude-3-5-sonnet', {
proxyUrl: 'https://api.myapp.com' // Routes through your proxy
});

See

https://github.com/baleybots/baleybots/tree/main/packages/proxy-server for server setup