v2026.11.3
All Bundles
Bundle

OpenAI API client. Supports Chat Completions (GPT-4o, o1, etc.), Embeddings, Image Generation (DALL-E), and function/tool calling. Set OPENAI_API_KEY environment variable before use. Compile with -lib openai.

EndPoint

OpenAI endpoint

Operations

GetApiKey # function

Reads API from 'api_key.dat'

function : GetApiKey() ~ String

Return

TypeDescription
StringAPI key

GetBaseUrl # function

Get the base URL

function : GetBaseUrl() ~ String

Return

TypeDescription
Stringbase

GetLastError # function

Get the last error

function : GetLastError() ~ String

Return

TypeDescription
Stringlast error

NoReply # function

Checks whether a request got an answer, recording the failure as the last error if not. A refused or dropped connection is a Nil response over HTTP and a response with status 0 and no content over HTTPS.

function : NoReply(response:Web.HTTP.Response) ~ Bool

Parameters

NameTypeDescription
responseResponseHTTP response, or Nil

Return

TypeDescription
Booltrue if there was no answer

ParseBody # function

Parses a response body, recording a failure as the last error. A body that is not JSON, or that carries an 'error' object, yields Nil; an 'error' that is null (the Responses API sends one on success) is not a failure.

function : ParseBody(body:String) ~ JsonElement

Parameters

NameTypeDescription
bodyStringresponse body

Return

TypeDescription
JsonElementparsed JSON, or Nil on failure

ParseErrorMessage # function

Reads the message of an error response. The 'error' member is an object with a 'message' on the documented path, but a gateway may send a plain string, an object without a 'message', or null.

function : ParseErrorMessage(response_json:JsonElement) ~ String

Parameters

NameTypeDescription
response_jsonJsonElementparsed response

Return

TypeDescription
Stringerror message, never Nil

ResponseText # function

Reads a response body as text. A reply with no body (an HTTP 204, a proxy error page without content) has no content bytes to read.

function : ResponseText(response:Web.HTTP.Response) ~ String

Parameters

NameTypeDescription
responseResponseHTTP response, or Nil

Return

TypeDescription
Stringbody text, or an empty string if the response has no body

SetApiKey # function

Set the API file key path

function : SetApiKey(api_key:String) ~ Nil

Parameters

NameTypeDescription
api_keyStringAPI file key path

SetBaseUrl # function

Set the base URL

function : SetBaseUrl(base_url:String) ~ Nil

Parameters

NameTypeDescription
base_urlStringbase URL