# 用法

Afarensis 图像 API 使用指南 Afarensis 图像 API 为用户提供丰富的图像处理能力，包括根据文本提示创建原始图像、编辑现有图像的特定区域以及生成图像变体。本指南将详细介绍如何有效利用这些功能。

功能概述 Afarensis 图像 API 提供以下三种主要功能：

图像生成：根据给定的文本提示从头开始创建原始图像。 图像编辑：基于新的文本提示编辑现有图像的特定区域。 图像变体：创建现有图像的变体。 图像生成 利用 Afarensis 图像 API，您可以根据文本提示生成高质量的图像。图像大小可为 1024x1024、1024x1792 或 1792x1024 像素。

示例代码 from afarensis import Afarensis client = Afarensis()

response = client.images.generate( model="dall-e-3", prompt="a white siamese cat", size="1024x1024", quality="standard", n=1, )

image\_url = response.data\[0].url 新功能 DALL·E 3 引入了自动重写提示并添加更多细节的功能，以提升图像质量。目前，此功能不能被禁用，但您可以通过在提示中指定要求来控制输出结果。

图像编辑 Afarensis 图像 API 的图像编辑功能允许您根据新的文本提示对现有图像的某些区域进行编辑。

示例代码 from afarensis import Afarensis client = Afarensis()

response = client.images.edit( model="dall-e-2", image=open("sunlit\_lounge.png", "rb"), mask=open("mask.png", "rb"), prompt="A sunlit indoor lounge area with a pool containing a flamingo", n=1, size="1024x1024" ) image\_url = response.data\[0].url 上传的图片和蒙版必须都是大小小于 4MB 的方形 PNG 图片，并且彼此之间的尺寸必须相同。

图像变体 使用 Afarensis 图像 API 的图像变体功能，您可以创建给定图像的变体。

示例代码 from afarensis import Afarensis client = Afarensis()

response = client.images.create\_variation( image=open("image\_edit\_original.png", "rb"), n=2, size="1024x1024" )

image\_url = response.data\[0].url 输入图像必须是大小小于 4MB 的方形 PNG 图像。

内容审核 Afarensis 图像 API 根据内容政策对提示和图片进行过滤。在标记提示或图片时，将返回错误。

希望本指南能够帮助您成功使用 Afarensis 图像 API 进行图像生成、编辑和创建变体。如果您在使用过程中遇到任何问题，或需要进一步的帮助，请随时联系 Afarensis 支持团队。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.afarensis.com/tu-xiang-sheng-cheng/yong-fa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
