Skip to content

@chinmaymk/aikit v0.0.40


@chinmaymk/aikit / callProxyProvider

Function: callProxyProvider()

callProxyProvider(request): AsyncIterable<string>

Defined in: providers/proxy.ts:221

Resolves a proxy request to a Server-Sent Events (SSE) stream. This is the core function backends use to handle proxy requests.

Parameters

request

ProxyRequest<GenerationProviderType> & object

The proxy request object, including provider type, options, messages, and an API key.

Returns

AsyncIterable<string>

An async iterable that yields SSE-formatted strings.

Example

typescript
// In your backend server (e.g., Express)
app.post('/ai/proxy', async (req, res) => {
  const requestWithApiKey = { ...req.body, providerOptions: { apiKey: '...' } };
  const stream = callProxyProvider(requestWithApiKey);

  res.setHeader('Content-Type', 'text/event-stream');
  for await (const chunk of stream) {
    res.write(chunk);
  }
  res.end();
});

Released under the MIT License.