Anthropic Messages API client (Claude). Plain and multi-turn chat with a system prompt, tool use, streaming over server-sent events, structured (JSON) output through a forced tool, and extended-thinking blocks. Responses and errors follow the other AI client libraries: a failed call returns Nil and EndPoint->GetLastError() says why. The key comes from SetApiKey, the ANTHROPIC_API_KEY environment variable, or anthropic_api_key.dat in the working directory. Requests go over HTTPS. Compile with -lib anthropic.
EndPoint
Anthropic endpoint settings, the API key and the last error
Operations
GetApiKey # function
Gets the API key: the one set with SetApiKey, else the ANTHROPIC_API_KEY environment variable, else the first line of anthropic_api_key.dat in the working directory.
function : GetApiKey() ~ StringReturn
| Type | Description |
|---|---|
| String | API key, or Nil with the last error set |
GetBaseUrl # function
Gets the API base URL
function : GetBaseUrl() ~ StringReturn
| Type | Description |
|---|---|
| String | base URL |
GetCertificate # function
Gets the pinned certificate file
function : GetCertificate() ~ StringReturn
| Type | Description |
|---|---|
| String | PEM file, or Nil |
GetLastError # function
Get the last error
function : GetLastError() ~ StringReturn
| Type | Description |
|---|---|
| String | last error, or Nil when the last call succeeded |
ParseBody # function
Parse a response body. Nil, with the last error set, when the body is not JSON or is an error object ({"type":"error","error":{"type":...,"message":...}}).
function : ParseBody(body:String) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| body | String | response text |
Return
| Type | Description |
|---|---|
| JsonElement | parsed element, or Nil |
SetApiKey # function
Sets the API key, overriding the environment and the key file
function : SetApiKey(api_key:String) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| api_key | String | API key |
SetBaseUrl # function
Sets the API base URL (default https://api.anthropic.com/v1), for a gateway or proxy
function : SetBaseUrl(base_url:String) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| base_url | String | base URL without a trailing slash; it must be https |
SetCertificate # function
Pins the certificate a gateway or test server presents, a PEM file used as the trust anchor in place of the system store. Leave it unset for api.anthropic.com.
function : SetCertificate(pem:String) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| pem | String | PEM file, or Nil to use the system store |