API client
The Zak_ai API client layer consists of two classes:
\Wegewerk\— low-level PSR HTTP wrapperAi3Core\ Api\ Zak Ai Client \Wegewerk\— account-level operationsAi3Core\ Api\ Zak Ai Account
Both classes are registered as services and can be injected via constructor DI.
ZakAiClient
ZakAiClient handles authentication and the raw HTTP layer. It reads
credentials from the environment at construction time (see
Environment variables). The base URL defaults to
https://www.zak-ai.com/api/v1/.
Public methods:
| Method | Description |
|---|---|
postJson(string $path, array $payload, ...) | Sends a JSON POST and returns the decoded response.
Appends model to the payload automatically. |
putJson(string $path, array $payload, ...) | Sends a JSON PUT. |
getJson(string $path, ...) | Sends a GET request (no body). |
hasApikey(): bool | Returns true if ZAKAI_API_KEY is non-empty. |
hasSecret(): bool | Returns true if ZAKAI_SECRET is non-empty. |
All request methods accept optional $extraHeaders and a
$requireAuth flag. When $requireAuth is true (default) and
no API key is set, a \RuntimeException is thrown before the request
is sent.
ZakAiAccount
ZakAiAccount wraps the account-related endpoints:
| Method | Description |
|---|---|
requestApikey(mixed $email, string $secret) | POST /accounts — request a new API key. |
confirmApikey() | PUT /accounts — confirm the pending API key. |
queryCredits(): mixed | GET /credits — return the current credit balance. |
clientHasApikey(): bool | Proxy for ZakAiClient::hasApikey(). |
clientHasSecret(): bool | Proxy for ZakAiClient::hasSecret(). |
Note
requestApikey() and confirmApikey() are called internally
by the Zak_ai management view in the
backend module. Direct calls by other Code is not intended.