request<>(credentials: Credentials,options: Options<I>,): Promise<T>
Send a HTTP request and, if 2xx, parse the JSON response as T object type.
The request body (options.body) is required if I is defined, otherwise I is inferred.
NOTE: The Response is thrown if not 2xx status!
Usage
Usage
import * as OpenAI from '@agent/openai'; let ctx = OpenAI.credentials({ apikey: '...', }); try { let reply = await OpenAI.request<OpenAI.Completion.Output>(ctx, { method: 'POST', path: '/completions', body: { model: '...', prompt: '...', } satisfies OpenAI.Completion.Request, }); console.assert(reply.object === 'text_completion'); } catch (err) { if (err instanceof Response) { console.log('OpenAI Error', err.status, await err.json()); } else { // ... } }
credentials: Credentials