Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/CrowdinApiClient/Api/AiApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use CrowdinApiClient\Model\AiProviderModel;
use CrowdinApiClient\Model\AiProxyChatCompletion;
use CrowdinApiClient\Model\AiReport;
use CrowdinApiClient\Model\AiRequestLog;
use CrowdinApiClient\Model\AiSettings;
use CrowdinApiClient\Model\AiSnippet;
use CrowdinApiClient\Model\AiTranslation;
Expand Down Expand Up @@ -447,6 +448,37 @@ public function downloadReport(int $userId, string $aiReportId): ?DownloadFile
return $this->_get($path, DownloadFile::class);
}

/**
* List AI Request Logs
* @link https://developer.crowdin.com/api/v2/#operation/api.ai.requestLogs.getMany API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.requestLogs.getMany API Documentation Enterprise
*
* @param int $userId
* @param array $params
* string $params[requestId] Filter by request identifier<br>
* integer $params[projectId] Filter by project<br>
* integer $params[userId] Filter by the user attributed to the AI request<br>
* integer $params[aiProviderId] Filter by AI provider<br>
* string $params[model] Filter by model name<br>
* string $params[sourceAction] Filter by the feature or channel that produced the request. Enum: "ai_proxy" "ai_gateway" "ai_translate_strings" "ai_file_translate" "ai_prompt_completion" "pre_translate:manual" "pre_translate:workflow" "ai_alignment" "qa_check" "ai_suggestion" "advisor"<br>
* string $params[promptAction] Filter by prompt action<br>
* string $params[statuses] Comma-separated request statuses. Enum: "pending" "success" "error" "timeout"<br>
* boolean $params[systemCredentials] Filter by whether system-provided credentials were used<br>
* boolean $params[isAutoTriggered] Filter by whether the request was triggered automatically<br>
* string $params[tokenName] Filter by personal access token name<br>
* string $params[oauthClientId] Filter by OAuth client identifier<br>
* string $params[createdAfter] Return logs created after this date-time<br>
* string $params[createdBefore] Return logs created before this date-time<br>
* integer $params[limit]<br>
* integer $params[offset]
* @return ModelCollection
*/
public function listRequestLogs(int $userId, array $params = []): ModelCollection
{
$path = sprintf('users/%d/ai/request-logs', $userId);
return $this->_list($path, AiRequestLog::class, $params);
}

/**
* Get AI Settings
* @link https://developer.crowdin.com/api/v2/#operation/api.users.ai.settings.get API Documentation
Expand Down
30 changes: 30 additions & 0 deletions src/CrowdinApiClient/Api/Enterprise/AiApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use CrowdinApiClient\Model\AiProviderModel;
use CrowdinApiClient\Model\AiProxyChatCompletion;
use CrowdinApiClient\Model\AiReport;
use CrowdinApiClient\Model\AiRequestLog;
use CrowdinApiClient\Model\AiSettings;
use CrowdinApiClient\Model\AiSnippet;
use CrowdinApiClient\Model\AiTranslation;
Expand Down Expand Up @@ -412,6 +413,35 @@ public function downloadReport(string $aiReportId): ?DownloadFile
return $this->_get($path, DownloadFile::class);
}

/**
* List AI Request Logs
* @link https://developer.crowdin.com/api/v2/#operation/api.ai.requestLogs.getMany API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.requestLogs.getMany API Documentation Enterprise
*
* @param array $params
* string $params[requestId] Filter by request identifier<br>
* integer $params[projectId] Filter by project<br>
* integer $params[userId] Filter by the user attributed to the AI request<br>
* integer $params[aiProviderId] Filter by AI provider<br>
* string $params[model] Filter by model name<br>
* string $params[sourceAction] Filter by the feature or channel that produced the request. Enum: "ai_proxy" "ai_gateway" "ai_translate_strings" "ai_file_translate" "ai_prompt_completion" "pre_translate:manual" "pre_translate:workflow" "ai_alignment" "qa_check" "ai_suggestion" "advisor"<br>
* string $params[promptAction] Filter by prompt action<br>
* string $params[statuses] Comma-separated request statuses. Enum: "pending" "success" "error" "timeout"<br>
* boolean $params[systemCredentials] Filter by whether system-provided credentials were used<br>
* boolean $params[isAutoTriggered] Filter by whether the request was triggered automatically<br>
* string $params[tokenName] Filter by personal access token name<br>
* string $params[oauthClientId] Filter by OAuth client identifier<br>
* string $params[createdAfter] Return logs created after this date-time<br>
* string $params[createdBefore] Return logs created before this date-time<br>
* integer $params[limit]<br>
* integer $params[offset]
* @return ModelCollection
*/
public function listRequestLogs(array $params = []): ModelCollection
{
return $this->_list('ai/request-logs', AiRequestLog::class, $params);
}

/**
* Get AI Settings
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.ai.settings.get API Documentation
Expand Down
230 changes: 230 additions & 0 deletions src/CrowdinApiClient/Model/AiRequestLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<?php

declare(strict_types=1);

namespace CrowdinApiClient\Model;

class AiRequestLog extends BaseModel
{
/** @var int */
protected $id;

/** @var string */
protected $requestId;

/** @var string */
protected $createdAt;

/** @var string */
protected $status;

/** @var int|null */
protected $httpStatus;

/** @var string */
protected $model;

/** @var string */
protected $sourceAction;

/** @var string|null */
protected $promptAction;

/** @var bool */
protected $systemCredentials;

/** @var bool */
protected $isAutoTriggered;

/** @var int|null */
protected $durationMs;

/** @var int|null */
protected $inputTokens;

/** @var int|null */
protected $outputTokens;

/** @var float|null */
protected $totalCost;

/** @var int|null */
protected $userId;

/** @var int|null */
protected $projectId;

/** @var int|null */
protected $promptId;

/** @var int */
protected $aiProviderId;

/** @var string|null */
protected $tokenName;

/** @var string|null */
protected $oauthClientId;

/** @var string|null */
protected $oauthClientName;

/** @var string|null */
protected $ip;

/** @var string|null */
protected $userAgent;

/** @var string|null */
protected $error;

public function __construct(array $data = [])
{
parent::__construct($data);

$this->id = (int)$this->getDataProperty('id');
$this->requestId = (string)$this->getDataProperty('requestId');
$this->createdAt = (string)$this->getDataProperty('createdAt');
$this->status = (string)$this->getDataProperty('status');
$this->httpStatus = $this->getDataProperty('httpStatus');
$this->model = (string)$this->getDataProperty('model');
$this->sourceAction = (string)$this->getDataProperty('sourceAction');
$this->promptAction = $this->getDataProperty('promptAction');
$this->systemCredentials = (bool)$this->getDataProperty('systemCredentials');
$this->isAutoTriggered = (bool)$this->getDataProperty('isAutoTriggered');
$this->durationMs = $this->getDataProperty('durationMs');
$this->inputTokens = $this->getDataProperty('inputTokens');
$this->outputTokens = $this->getDataProperty('outputTokens');
$this->totalCost = $this->getDataProperty('totalCost');
$this->userId = $this->getDataProperty('userId');
$this->projectId = $this->getDataProperty('projectId');
$this->promptId = $this->getDataProperty('promptId');
$this->aiProviderId = (int)$this->getDataProperty('aiProviderId');
$this->tokenName = $this->getDataProperty('tokenName');
$this->oauthClientId = $this->getDataProperty('oauthClientId');
$this->oauthClientName = $this->getDataProperty('oauthClientName');
$this->ip = $this->getDataProperty('ip');
$this->userAgent = $this->getDataProperty('userAgent');
$this->error = $this->getDataProperty('error');
}

public function getId(): int
{
return $this->id;
}

public function getRequestId(): string
{
return $this->requestId;
}

public function getCreatedAt(): string
{
return $this->createdAt;
}

public function getStatus(): string
{
return $this->status;
}

public function getHttpStatus(): ?int
{
return $this->httpStatus;
}

public function getModel(): string
{
return $this->model;
}

public function getSourceAction(): string
{
return $this->sourceAction;
}

public function getPromptAction(): ?string
{
return $this->promptAction;
}

public function isSystemCredentials(): bool
{
return $this->systemCredentials;
}

public function isAutoTriggered(): bool
{
return $this->isAutoTriggered;
}

public function getDurationMs(): ?int
{
return $this->durationMs;
}

public function getInputTokens(): ?int
{
return $this->inputTokens;
}

public function getOutputTokens(): ?int
{
return $this->outputTokens;
}

public function getTotalCost(): ?float
{
return $this->totalCost;
}

public function getUserId(): ?int
{
return $this->userId;
}

public function getProjectId(): ?int
{
return $this->projectId;
}

public function getPromptId(): ?int
{
return $this->promptId;
}

public function getAiProviderId(): int
{
return $this->aiProviderId;
}

public function getTokenName(): ?string
{
return $this->tokenName;
}

public function getOauthClientId(): ?string
{
return $this->oauthClientId;
}

public function getOauthClientName(): ?string
{
return $this->oauthClientName;
}

public function getIp(): ?string
{
return $this->ip;
}

public function getUserAgent(): ?string
{
return $this->userAgent;
}

public function getError(): ?string
{
return $this->error;
}
}
Loading
Loading