---
title: "API client"
manual: "Ai3 Core"
version: "main"
permalink: "https://docs.typo3.org/permalink/wegewerk/ai3_core:developer-api-client@main"
source: "Developer/ApiClient.rst"
rendered: "2026-10-23T16:30:49+00:00"
---

# API client {#developer-api-client}

The Zak_ai API client layer consists of two classes:

-   `\Wegewerk\Ai3Core\Api\ZakAiClient` — low-level PSR HTTP wrapper
-   `\Wegewerk\Ai3Core\Api\ZakAiAccount` — account-level operations

Both classes are registered as services and can be injected via
constructor DI.

## ZakAiClient {#developer-api-client-zak-ai-client}

`ZakAiClient` handles authentication and the raw HTTP layer. It reads
credentials from the environment at construction time (see
[Environment variables](https://docs.typo3.org/permalink/wegewerk/ai3_core:configuration-env-vars@main)). 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 {#developer-api-client-zak-ai-account}

`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](https://docs.typo3.org/permalink/wegewerk/ai3_core:usage-zakaimgmt@main) in the
> backend module. Direct calls by other Code is not intended.
