Skip to main content

ACEngine Client SDK

用于调用 ACE 美学计算服务的 Python SDK。支持 MNet / ICAA17K 的私有资源调用、IQA 图片/视频异步任务,以及现有单项评分和图像/视频处理接口。

需要 Python 3.9 或更新版本。

安装

python -m pip install ace-engine-sdk

升级到最新版本:

python -m pip install --upgrade ace-engine-sdk

安装后的导入名称为 ace_engine。

快速开始

密钥放在环境变量里,勿写进共享代码。示例占位符需要替换成控制台颁发的有效凭证:

export ACE_ENGINE_ACCESS_KEY_ID="your-key-id"
export ACE_ENGINE_ACCESS_KEY_SECRET="your-key-secret"

Windows PowerShell:

$env:ACE_ENGINE_ACCESS_KEY_ID="your-key-id"
$env:ACE_ENGINE_ACCESS_KEY_SECRET="your-key-secret"
import os
from ace_engine import AceClient

with AceClient(
    access_key_id=os.environ["ACE_ENGINE_ACCESS_KEY_ID"],
    access_key_secret=os.environ["ACE_ENGINE_ACCESS_KEY_SECRET"],
    raise_for_errors=True,
) as client:
    response = client.mnet("photo.png")
    print(response["data"])  # 保留后端原始模型字段
    print(response["meta"])  # requestId、assetId、costCents、durationMs、replayed 等

默认服务为 https://ace-aesthetics.cn,接口前缀为 /ibt。base_url 也接受 https://ace-aesthetics.cn/ibt,不会重复拼接前缀。自建网关可以配置 base_url 和 api_prefix;只有直接连接不带统一前缀的网关时才使用 api_prefix=""。

上传一次,调用多个模型

下面使用 client 的片段应放在上面的 with AceClient(...) as client: 代码块内;离开代码块后连接已关闭。

uploaded = client.upload_asset("photo.png")
asset_id = uploaded["data"]["assetId"]

mnet_key = client.new_idempotency_key()
response = client.mnet(asset_id=asset_id, idempotency_key=mnet_key)

# 新的模型调用意图使用新的幂等键
icaa_key = client.new_idempotency_key()
response = client.icaa17k(asset_id=asset_id, idempotency_key=icaa_key)

# 检查资源 / 查询已经提交的调用,不重新执行模型
asset = client.get_asset(asset_id)
status = client.get_inference(response["meta"]["requestId"])

client.infer("mnet", asset_id, idempotency_key=...) 和 client.infer("icaa17k", ...) 提供相同的底层入口。mnet("photo.png")、icaa17k("photo.png") 自动先上传再调用。

import_asset(image_url) 将网址交给服务端的允许来源检查;SDK 不下载任意网址,也不绕过后端来源限制。资源属于凭证对应的用户/团队,会按服务端保留策略过期;不能假定资源永久有效。

幂等、错误和计费

一次逻辑调用使用一个幂等键,网络超时或响应丢失后的恢复必须沿用原键。不同模型或不同图片使用新键。

from ace_engine import AceError

key = client.new_idempotency_key()  # 调用前由业务持久化保存 key 和 asset_id
try:
    response = client.infer("mnet", asset_id, idempotency_key=key)
except AceError as error:
    print(error.code, error.request_id, error.idempotency_key)
    # 有 request_id 时先 get_inference(request_id) 查看 RUNNING / SETTLING / SUCCEEDED / FAILED。
    # 状态允许恢复时,再使用同一个模型、asset_id、key 调用 infer。
    # 不要因超时直接换一个新 key。

SDK 不会自动重试模型调用。MNet / ICAA17K 的响应包含服务端返回的 costCents 等计费字段。replayed=True 表示返回同一次调用的已有结果,不会再次计费。

默认 raise_for_errors=False,兼容 0.1 的字典返回方式,调用方应检查 code / success。HTTP 和业务错误保留原始业务码、说明、请求编号和 HTTP 状态(httpStatus)。本地或网络错误使用 errorType 区分。

网络/协议异常可能带 outcomeUnknown=True:这表示客户端不能确认提交结果,不能据此推断模型未运行或未扣款。错误中的 meta 保留可用的 assetId、idempotencyKey、taskId 等恢复信息。密钥和令牌会从 SDK 返回的错误中脱敏;SDK 不打印请求或凭证,不跟随重定向发送凭证。

raise_for_errors=True 会抛出 AceError,其 .response 保留相同的错误字典。响应数据及费用字段以实际部署版本为准。

IQA 异步评估

# 一张或多张图片;默认等待完成
response = client.iqa(
    ["photo1.png", "photo2.jpg"],
    selections=["sharpness", "exposure", "contrast", "noise"],
    wait_timeout=300,
)
print(response["data"]["status"])
print(response["data"].get("result"))

图片每任务最多 50 张,视频每任务 1 个。图片单文件上限 20 MiB,视频 100 MiB;还受服务端实际配额限制。支持的指标为:sharpness、color_accuracy、saturation、exposure、contrast、noise、holistic、overall_iqa。holistic 需要至少一项基础指标;视频不支持 overall_iqa。

异步提交、查询和取消:

asset = client.upload_iqa_asset("clip.mp4", kind="video")
asset_ids = [asset["data"]["assetId"]]
key = client.new_idempotency_key()
created = client.create_iqa_task(
    asset_ids, kind="video", selections=["exposure"], idempotency_key=key,
)
task_id = created["data"]["taskId"]

response = client.get_iqa_task(task_id)
response = client.wait_iqa_task(task_id, wait_timeout=600, poll_interval=2)
# client.cancel_iqa_task(task_id)  # 只有显式调用才请求取消
# client.list_iqa_tasks()

也可以 client.iqa("photo.png", selections=["exposure"], wait=False),返回已创建的任务。wait_timeout 只限制客户端等待,超时不会自动取消、重建或重新扣费;保存错误 meta.taskId 后继续查询。

SUCCEEDED 是完成,PARTIAL 表示部分结果可用(需要检查任务里的 errors),FAILED / CANCELLED 在等待接口中作为错误返回。查询接口保留服务端原始状态。等待网络中断后继续查询原任务,不要重新上传并创建另一个任务。若创建响应丢失,应使用原 asset_ids、指标、kind 和幂等键恢复;IQA 重传文件会产生新资源 ID,不能假定与原任务等价。

MNet/ICAA 的资源与 IQA 的资源是不同接口管理的资源,不能混用 ID。IQA 输出可能包含短期签名图片/CSV/视频链接;保留签名参数,失效后重新查询任务,SDK 不向这些链接转发账户凭证。

get_iqa_config() 读取当前配置;configure_iqa(config) 用于更新完整的权重和阈值配置。单次 iqa() 调用不修改账户默认设置。

兼容的单项文件接口

以下方法接受本地图片,继续调用对应的 /api/file/... 接口:

方法 用途
sharpness(path) 清晰度
color(path) 色彩
contrast(path) 对比度
noise(path) 噪声
exposure(path) 曝光
holistic(path) 综合质量
evaluate_all(path) 服务端定义的综合评估
overall_iqa(path) 高分辨率整体质量
roc4mllm(path) 多模态评价
physique(path) / paa(path) 体态评价
human(path) 人像评价

这些接口使用 API-Key 鉴权,响应结构随模型而异。调用需要相应的模型权限及账户余额。

MNet / ICAA 默认走新资源接口;只有明确连接旧版服务时才使用 client.mnet(path, legacy=True) 或 client.icaa17k(path, legacy=True)。普通单项文件接口没有统一幂等保障,超时后不能盲目重发;SDK 不自动重试。

图像和视频输出

from ace_engine import BinaryResult

result = client.creative_crop("photo.jpg")
if isinstance(result, BinaryResult):
    result.save("crop.jpg")  # 默认拒绝覆盖已有文件

# 返回 BinaryResult,保留真实 Content-Type
result = client.acellm("photo.jpg", selections=["exposure"])
result = client.highlight("clip.mp4", query="a person running")

# JSON 响应
result = client.videomamba("clip.mp4", query="a person running")

二进制成功返回 BinaryResult(content, content_type, request_id);失败仍按统一错误机制处理,不把 JSON 报错写成图片或视频。内容在内存中,只有显式 .save() 才写文件;覆盖需要 overwrite=True。

网站登录令牌

已有有效普通用户 JWT 时,可使用 AceClient(token=token) 访问新资源、模型调用和正式 IQA 任务接口。SDK 不负责登录、验证码或刷新令牌。API-Key 与 JWT 必须选择一种,不能混传;旧的单项文件接口需要 API-Key,不自动切换鉴权身份。

反馈问题

遇到安装或调用问题,请在 GitHub Issues 提交 Python 版本、SDK 版本、错误信息及可复现的示例。请勿附上 API-Key、Secret 或登录令牌。

Metadata

Release files for ace-engine-sdk 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ace-engine-sdk 0.2.1
File Size Uploaded Provenance Actions
ace_engine_sdk-0.2.1.tar.gz 26.2 kB With provenance Details for ace_engine_sdk-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ace-engine-sdk 0.2.1
File Interpreter ABI Platform Actions
ace_engine_sdk-0.2.1-py3-none-any.whl Python 3 none any Details for ace_engine_sdk-0.2.1-py3-none-any.whl

Total release size: 39.9 kB

Release files / ace_engine_sdk-0.2.1.tar.gz

Download URL ace_engine_sdk-0.2.1.tar.gz
Size 26.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ac28fbb286f739ad3c4ea25041898847eb5db03ebc6b647336a503bbd1faa060
BLAKE2b-256 checksum
How to use checksums
080661b8178bd03f4e002c0d7f307f42424db30f3cd57a856cb292dc9b1c66ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / ace_engine_sdk-0.2.1-py3-none-any.whl

Download URL ace_engine_sdk-0.2.1-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ec13a321d81db068e9cb824614db6822dcadcfde777561313de92781f06ab56
BLAKE2b-256 checksum
How to use checksums
74d0f4bce317f56ba9c6da9823855a16df908cb18d29e6ab0f4d63c4fd2a671c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for ace-engine-sdk 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ace_engine_sdk-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page