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() ~ StringReturn
| Type | Description |
|---|---|
| String | API key |
GetBaseUrl # function
Get the base URL
function : GetBaseUrl() ~ StringReturn
| Type | Description |
|---|---|
| String | base |
GetLastError # function
Get the last error
function : GetLastError() ~ StringReturn
| Type | Description |
|---|---|
| String | last 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) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| response | Response | HTTP response, or Nil |
Return
| Type | Description |
|---|---|
| Bool | true 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) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| body | String | response body |
Return
| Type | Description |
|---|---|
| JsonElement | parsed 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) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| response_json | JsonElement | parsed response |
Return
| Type | Description |
|---|---|
| String | error 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) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| response | Response | HTTP response, or Nil |
Return
| Type | Description |
|---|---|
| String | body text, or an empty string if the response has no body |