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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.19.0"
".": "0.20.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 27
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api/moderation-api-2a9024f55f158ede9f9d4811ab4035e470afc920d0f15513da6603d011b2bef7.yml
openapi_spec_hash: cc3275c46438bd043ac96e669e27276f
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api/moderation-api-cbf656f40e43acf60d9596f78204f031dc8c7205626df8f05ce8e88bcf49b597.yml
openapi_spec_hash: 23be5a56248a1a575b34833eb7e7fe49
config_hash: 9d144cc6c49d3fd53e5b4472c1e22165
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.20.0 (2026-06-02)

Full Changelog: [v0.19.0...v0.20.0](https://github.com/moderation-api/sdk-php/compare/v0.19.0...v0.20.0)

### Features

* **api:** api update ([247b4cf](https://github.com/moderation-api/sdk-php/commit/247b4cf8bace8c77249b90de09e3eccfa7692e2e))

## 0.19.0 (2026-06-01)

Full Changelog: [v0.18.0...v0.19.0](https://github.com/moderation-api/sdk-php/compare/v0.18.0...v0.19.0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The REST API documentation can be found on [docs.moderationapi.com](https://docs
<!-- x-release-please-start-version -->

```
composer require "moderation-api/sdk-php 0.19.0"
composer require "moderation-api/sdk-php 0.20.0"
```

<!-- x-release-please-end -->
Expand Down
7 changes: 5 additions & 2 deletions src/Content/ContentSubmitParams/Policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ModerationAPI\Content\ContentSubmitParams\Policy\Cannabis;
use ModerationAPI\Content\ContentSubmitParams\Policy\CodeAbuse;
use ModerationAPI\Content\ContentSubmitParams\Policy\Crypto;
use ModerationAPI\Content\ContentSubmitParams\Policy\FaceDetection;
use ModerationAPI\Content\ContentSubmitParams\Policy\Flirtation;
use ModerationAPI\Content\ContentSubmitParams\Policy\Guideline;
use ModerationAPI\Content\ContentSubmitParams\Policy\Hate;
Expand Down Expand Up @@ -57,6 +58,7 @@
* @phpstan-import-type SelfHarmShape from \ModerationAPI\Content\ContentSubmitParams\Policy\SelfHarm
* @phpstan-import-type SpamShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Spam
* @phpstan-import-type LowQualityContentShape from \ModerationAPI\Content\ContentSubmitParams\Policy\LowQualityContent
* @phpstan-import-type FaceDetectionShape from \ModerationAPI\Content\ContentSubmitParams\Policy\FaceDetection
* @phpstan-import-type SelfPromotionShape from \ModerationAPI\Content\ContentSubmitParams\Policy\SelfPromotion
* @phpstan-import-type PoliticalShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Political
* @phpstan-import-type ReligionShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Religion
Expand All @@ -66,8 +68,8 @@
* @phpstan-import-type URLRiskShape from \ModerationAPI\Content\ContentSubmitParams\Policy\URLRisk
* @phpstan-import-type GuidelineShape from \ModerationAPI\Content\ContentSubmitParams\Policy\Guideline
*
* @phpstan-type PolicyVariants = Toxicity|PersonalInformation|ToxicitySevere|Hate|Illicit|IllicitDrugs|IllicitAlcohol|IllicitFirearms|IllicitTobacco|IllicitGambling|Cannabis|Adult|Crypto|Sexual|Flirtation|Profanity|Violence|SelfHarm|Spam|LowQualityContent|SelfPromotion|Political|Religion|CodeAbuse|PiiMasking|URLMasking|URLRisk|Guideline
* @phpstan-type PolicyShape = PolicyVariants|ToxicityShape|PersonalInformationShape|ToxicitySevereShape|HateShape|IllicitShape|IllicitDrugsShape|IllicitAlcoholShape|IllicitFirearmsShape|IllicitTobaccoShape|IllicitGamblingShape|CannabisShape|AdultShape|CryptoShape|SexualShape|FlirtationShape|ProfanityShape|ViolenceShape|SelfHarmShape|SpamShape|LowQualityContentShape|SelfPromotionShape|PoliticalShape|ReligionShape|CodeAbuseShape|PiiMaskingShape|URLMaskingShape|URLRiskShape|GuidelineShape
* @phpstan-type PolicyVariants = Toxicity|PersonalInformation|ToxicitySevere|Hate|Illicit|IllicitDrugs|IllicitAlcohol|IllicitFirearms|IllicitTobacco|IllicitGambling|Cannabis|Adult|Crypto|Sexual|Flirtation|Profanity|Violence|SelfHarm|Spam|LowQualityContent|FaceDetection|SelfPromotion|Political|Religion|CodeAbuse|PiiMasking|URLMasking|URLRisk|Guideline
* @phpstan-type PolicyShape = PolicyVariants|ToxicityShape|PersonalInformationShape|ToxicitySevereShape|HateShape|IllicitShape|IllicitDrugsShape|IllicitAlcoholShape|IllicitFirearmsShape|IllicitTobaccoShape|IllicitGamblingShape|CannabisShape|AdultShape|CryptoShape|SexualShape|FlirtationShape|ProfanityShape|ViolenceShape|SelfHarmShape|SpamShape|LowQualityContentShape|FaceDetectionShape|SelfPromotionShape|PoliticalShape|ReligionShape|CodeAbuseShape|PiiMaskingShape|URLMaskingShape|URLRiskShape|GuidelineShape
*/
final class Policy implements ConverterSource
{
Expand Down Expand Up @@ -99,6 +101,7 @@ public static function variants(): array
SelfHarm::class,
Spam::class,
LowQualityContent::class,
FaceDetection::class,
SelfPromotion::class,
Political::class,
Religion::class,
Expand Down
144 changes: 144 additions & 0 deletions src/Content/ContentSubmitParams/Policy/FaceDetection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php

declare(strict_types=1);

namespace ModerationAPI\Content\ContentSubmitParams\Policy;

use ModerationAPI\Content\ContentSubmitParams\Policy\FaceDetection\Comparator;
use ModerationAPI\Core\Attributes\Optional;
use ModerationAPI\Core\Attributes\Required;
use ModerationAPI\Core\Concerns\SdkModel;
use ModerationAPI\Core\Contracts\BaseModel;

/**
* @phpstan-type FaceDetectionShape = array{
* id: 'face_detection',
* flag: bool,
* comparator?: null|Comparator|value-of<Comparator>,
* count?: int|null,
* threshold?: float|null,
* }
*/
final class FaceDetection implements BaseModel
{
/** @use SdkModel<FaceDetectionShape> */
use SdkModel;

/** @var 'face_detection' $id */
#[Required]
public string $id = 'face_detection';

#[Required]
public bool $flag;

/**
* Flag images that contain "at least" or "fewer than" the configured number of faces. Defaults to at_least.
*
* @var value-of<Comparator>|null $comparator
*/
#[Optional(enum: Comparator::class)]
public ?string $comparator;

/**
* Number of faces the comparator applies to. Defaults to 1, so the default rule flags any image containing a face.
*/
#[Optional]
public ?int $count;

#[Optional]
public ?float $threshold;

/**
* `new FaceDetection()` is missing required properties by the API.
*
* To enforce required parameters use
* ```
* FaceDetection::with(flag: ...)
* ```
*
* Otherwise ensure the following setters are called
*
* ```
* (new FaceDetection)->withFlag(...)
* ```
*/
public function __construct()
{
$this->initialize();
}

/**
* Construct an instance from the required parameters.
*
* You must use named parameters to construct any parameters with a default value.
*
* @param Comparator|value-of<Comparator>|null $comparator
*/
public static function with(
bool $flag,
Comparator|string|null $comparator = null,
?int $count = null,
?float $threshold = null,
): self {
$self = new self;

$self['flag'] = $flag;

null !== $comparator && $self['comparator'] = $comparator;
null !== $count && $self['count'] = $count;
null !== $threshold && $self['threshold'] = $threshold;

return $self;
}

/**
* @param 'face_detection' $id
*/
public function withID(string $id): self
{
$self = clone $this;
$self['id'] = $id;

return $self;
}

public function withFlag(bool $flag): self
{
$self = clone $this;
$self['flag'] = $flag;

return $self;
}

/**
* Flag images that contain "at least" or "fewer than" the configured number of faces. Defaults to at_least.
*
* @param Comparator|value-of<Comparator> $comparator
*/
public function withComparator(Comparator|string $comparator): self
{
$self = clone $this;
$self['comparator'] = $comparator;

return $self;
}

/**
* Number of faces the comparator applies to. Defaults to 1, so the default rule flags any image containing a face.
*/
public function withCount(int $count): self
{
$self = clone $this;
$self['count'] = $count;

return $self;
}

public function withThreshold(float $threshold): self
{
$self = clone $this;
$self['threshold'] = $threshold;

return $self;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace ModerationAPI\Content\ContentSubmitParams\Policy\FaceDetection;

/**
* Flag images that contain "at least" or "fewer than" the configured number of faces. Defaults to at_least.
*/
enum Comparator: string
{
case AT_LEAST = 'at_least';

case FEWER_THAN = 'fewer_than';
}
25 changes: 25 additions & 0 deletions src/Content/ContentSubmitResponse/Policy/ClassifierOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* flagged: bool,
* probability: float,
* type: 'classifier',
* data?: array<string,mixed>|null,
* flaggedFields?: list<string>|null,
* labels?: list<Label|LabelShape>|null,
* }
Expand All @@ -45,6 +46,14 @@ final class ClassifierOutput implements BaseModel
#[Required]
public float $probability;

/**
* Optional structured data produced by the policy. For face detection: { count, faces: [{ confidence, gender, age }] }.
*
* @var array<string,mixed>|null $data
*/
#[Optional(map: 'mixed')]
public ?array $data;

/**
* The keys of the flagged fields if submitting an object.
*
Expand Down Expand Up @@ -81,13 +90,15 @@ public function __construct()
*
* You must use named parameters to construct any parameters with a default value.
*
* @param array<string,mixed>|null $data
* @param list<string>|null $flaggedFields
* @param list<Label|LabelShape>|null $labels
*/
public static function with(
string $id,
bool $flagged,
float $probability,
?array $data = null,
?array $flaggedFields = null,
?array $labels = null,
): self {
Expand All @@ -97,6 +108,7 @@ public static function with(
$self['flagged'] = $flagged;
$self['probability'] = $probability;

null !== $data && $self['data'] = $data;
null !== $flaggedFields && $self['flaggedFields'] = $flaggedFields;
null !== $labels && $self['labels'] = $labels;

Expand Down Expand Up @@ -141,6 +153,19 @@ public function withType(string $type): self
return $self;
}

/**
* Optional structured data produced by the policy. For face detection: { count, faces: [{ confidence, gender, age }] }.
*
* @param array<string,mixed> $data
*/
public function withData(array $data): self
{
$self = clone $this;
$self['data'] = $data;

return $self;
}

/**
* The keys of the flagged fields if submitting an object.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
namespace ModerationAPI;

// x-release-please-start-version
const VERSION = '0.19.0';
const VERSION = '0.20.0';
// x-release-please-end