t0 = time.time() res = client.openai.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": "Reply with exactly: ADC_PY_SDK_OK"}], max_tokens=20, temperature=0, ) print("elapsed_ms", int((time.time() - t0) * 1000)) print("id", res["id"]) print("model", res["model"]) print("content", res["choices"][0]["message"]["content"]) print("usage", json.dumps({k: v for k, v in res["usage"].items() if k in ("prompt_tokens","completion_tokens","total_tokens")}))
程序运行结果:
1 2 3 4 5
elapsed_ms 2963 id chatcmpl-DldFdnIlhSUXINpupgsUmZL78MnBu model gpt-4o-mini content ADC_PY_SDK_OK usage {"prompt_tokens": 17, "completion_tokens": 7, "total_tokens": 24}
for chunk in client.openai.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": "Count from 1 to 5, separated by single spaces, no extra text."}], max_tokens=30, temperature=0, stream=True, ): if first_chunk_ms isNone: first_chunk_ms = int((time.time() - t0) * 1000) chunks += 1 delta = (chunk.get("choices") or [{}])[0].get("delta", {}).get("content") if delta: collected.append(delta)
t0 = time.time() res = client.images.generate( provider="nano-banana", model="nano-banana", prompt="A minimalist logo of a yellow banana on a white background, flat design", ) print("elapsed_ms", int((time.time() - t0) * 1000)) print("task_id", res.get("task_id")) print("trace_id", res.get("trace_id")) data = res.get("data") or [] if data: print("image_url", data[0].get("image_url"))
payload = { "model": "gpt-image-2", "prompt": "A cinematic portrait of a young woman standing in a convenience store at night, illuminated by soft pink and cyan neon signs through the window. Shot on 35mm film, shallow depth of field, slight grain, melancholic mood.", "size": "1024x1536" }
{ "success": true, "task_id": "ab58a5df-6f46-4874-bff6-93169e2849a3", "created": 1777048800, "data": [ { "revised_prompt": "A cinematic portrait of a young woman standing in a convenience store at night, illuminated by soft pink and cyan neon signs through the window. Shot on 35mm film, shallow depth of field, slight grain, melancholic mood.", "url": "https://platform.cdn.acedata.cloud/gpt-image/ab58a5df-6f46-4874-bff6-93169e2849a3_0.png" } ] }
payload = { "model": "gpt-image-2", "prompt": "A vintage travel poster of the Amalfi Coast, Italy. Stylized art-deco illustration of cliffside lemon-yellow houses cascading down to a turquoise sea, with a small white sailboat in the harbor. Bold typography at the top reads AMALFI and at the bottom ITALIA 1958. Limited color palette: cream, sea-blue, lemon yellow, terracotta. Slight paper-grain texture.", "size": "1024x1536" }
返回结果中的 url 字段对应的图片如下:
可以看到模型不仅准确还原了 Art Deco 海报的视觉风格,标题文字 AMALFI 与 ITALIA 1958 都被清晰、正确地渲染出来。
场景三:复杂构图与计数
下面这个提示词用来测试模型对“数量”和“位置”等结构化指令的遵循能力。
1 2 3 4 5
payload = { "model": "gpt-image-2", "prompt": "A wooden bookshelf consisting of three shelves: On the top shelf, there should be one book. On the second shelf, there should be three books. On the bottom shelf, there should be seven books. Soft warm lighting, photorealistic, cozy library atmosphere.", "size": "1024x1024" }
payload = { "model": "gpt-image-2", "prompt": "A soft, poetic children's book illustration of a small fox reading a book under a glowing mushroom in a moonlit forest. Watercolor and pencil texture, gentle pastel colors, dreamy atmosphere, hand-drawn feel.", "size": "1536x1024" }
{ "created": 0, "data": [ { "url": "https://platform.cdn.acedata.cloud/nanobanana/6870b330-65c4-436c-bb80-819fdae7a7a4.png", "revised_prompt": "a small red apple on a white table, photoreal" } ] }
{ "created": 1721626477, "data": [ { "revised_prompt": "A delightful image showcasing a young sea otter, who is born brown, with wide charming eyes. It is delightfully lying on its back, paddling in the calm sea waters. Its dense, velvety fur appears wet and shimmering, capturing the essence of its habitat. The small creature curiously plays with a sea shell with its small paws, looking absolutely innocent and charming in its natural environment.", "url": "https://dalleprodsec.blob.core.windows.net/private/images/5d98aa7c-80c6-4523-b571-fc606ad455b9/generated_00.png?se=2024-07-23T05%3A34%3A48Z&sig=GAz%2Bi3%2BkHOQwAMhxcv22tBM%2FaexrxPgT9V0DbNrL4ik%3D&ske=2024-07-23T08%3A41%3A10Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-07-16T08%3A41%3A10Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02" } ] }
返回结果一共有多个字段,介绍如下:
created,生成此次图像生成的 ID,用于唯一标识此次任务。
data,包含图像生成的结果信息。
其中 data 是包含了模型生成图片的具体信息,它里面的 url 是生成图片的详情链接,可以发现如图所示。
图片质量参数 quality
接下来将介绍如何设置图像生成结果的一些详细参数,其中图片质量参数 quality 包含俩种,第一个 standard 表示生成标准的图片,另一个 hd 表示创建的图像具有更精细的细节和更大的一致性。
{ "created": 1721636023, "data": [ { "revised_prompt": "A cute baby sea otter is lying playfully on its back in the water, with its fur looking glossy and soft. One of its tiny paws is reaching out curiously, and it has an expression of pure joy and warmth on its face as it looks up to the sky. Its body is surrounded by bubbles from its playful twirling in the water. A gentle breeze is playing with its fur making it look more charming. The scene portrays the tranquility and charm of marine life.", "url": "https://dalleprodsec.blob.core.windows.net/private/images/a93ee5e7-3abd-4923-8d79-dc9ef126da46/generated_00.png?se=2024-07-23T08%3A13%3A55Z&sig=wTXGYvUOwUIkaB2CxjK9ww%2FHjS8OwYUWcYInXYKwcAM%3D&ske=2024-07-23T11%3A32%3A05Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-07-16T11%3A32%3A05Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02" } ] }
{ "created": 1721636652, "data": [ { "revised_prompt": "A delightful depiction of a baby sea otter. The small mammal is captured in its natural habitat in the ocean, floating on its back. It has thick brown fur that is sleek and wet from the sea water. Its eyes are closed as if it is enjoying a moment of deep relaxation. The water around it is calm, reflecting the peacefulness of the scene. The background should hint at a diverse marine ecosystem, with visible strands of kelp floating on the surface, suggesting the baby otter's preferred environment.", "url": "https://dalleprodsec.blob.core.windows.net/private/images/9d625ac6-fd2b-42a9-84a6-8c99eb357ccf/generated_00.png?se=2024-07-23T08%3A24%3A24Z&sig=AXtYXowEakGxfRp8LhC2DwqL%2F07LhEDW40oCP%2BdTO8s%3D&ske=2024-07-23T18%3A00%3A45Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-07-16T18%3A00%3A45Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02" } ] }
{ "created": 1721637086, "data": [ { "revised_prompt": "A baby sea otter with soft, shiny fur and sparkling eyes floating playfully on calm ocean waters. This adorable creature is trippingly frolicking amidst small, gentle waves under a bright, clear, sunny sky. The tranquility of the sea contrasts subtly with the delightful energy of this young otter. The critter gamely clings to a tiny piece of driftwood, its small paws adorably enveloping the floating object.", "url": "https://dalleprodsec.blob.core.windows.net/private/images/6e48f701-7fd3-4356-839e-a2f6f0fe82d9/generated_00.png?se=2024-07-23T08%3A31%3A37Z&sig=4percxqTbUR1j3BQmkhvj%2FAhHzInKI%2FqiTo1MP69coI%3D&ske=2024-07-27T10%3A39%3A55Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-07-20T10%3A39%3A55Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02" } ] }
{ "created": 1721637575, "data": [ { "revised_prompt": "A charming depiction of a baby sea otter. The otter is seen resting serenely on its back amidst the gentle, blue ocean waves. The baby otter's fur is an endearing mix of soft greyish brown shades, glinting subtly in the muted sunlight. Its small paws are touching, lifted slightly towards the sky as if playing with an unseen object. Its round, expressive eyes are wide in curiosity, sparking with life and innocence. Use a realistic style to evoke the otter's natural habitat and its adorably fluffy exterior.", "url": "https://dalleprodsec.blob.core.windows.net/private/images/87792c5f-8b6d-412e-81dd-f1a1baa19bd2/generated_00.png?se=2024-07-23T08%3A39%3A47Z&sig=zzRAn30TqIKHdLVqZPUUuSJdjCYpoJdaGU6BeoA76Jo%3D&ske=2024-07-23T13%3A32%3A13Z&skoid=e52d5ed7-0657-4f62-bc12-7e5dbb260a96&sks=b&skt=2024-07-16T13%3A32%3A13Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02" } ] }
{ "created": 1721638071, "data": [ { "b64_json": "iVBORw0..............v//AQEAAP4AAAD+AAADAQAAAwEEA/4D//8Q/Pbw64mKbVTFoQAAAABJRU5ErkJggg==", "revised_prompt": "A charming image of a young baby sea otter. The otter is gently floating on a calm blue sea, basking in the warm, golden rays of sunlight streaming down from a clear sky above. The otter's fur is a rich chocolate brown, and it looks incredibly soft and fluffy. The otter's eyes are bright and expressive, filled with childlike curiosity and joy. It has small, pricked ears and a button-like nose which adds to its overall cuteness. In the sea around it, twinkling droplets of water can be seen, pepped up by the sunlight, the sight is certainly a delightful one." } ] }
异步回调
由于 OpenAI Images Generations API 生成图片的时间可能相对较长,如果 API 长时间无响应,HTTP 请求会一直保持连接,导致额外的系统资源消耗,所以本 API 也提供了异步回调的支持。
整体流程是:客户端发起请求的时候,额外指定一个 callback_url 字段,客户端发起 API 请求之后,API 会立马返回一个结果,包含一个 task_id 的字段信息,代表当前的任务 ID。当任务完成之后,生成图片的结果会通过 POST JSON 的形式发送到客户端指定的 callback_url,其中也包括了 task_id 字段,这样任务结果就可以通过 ID 关联起来了。
tx 0xfec08cc00a159ea1ec692b32faa9bf3d17595a986301169e689d94f58bc44151 status 1 block 46726704 explorer https://basescan.org/tx/0xfec08cc00a159ea1ec692b32faa9bf3d17595a986301169e689d94f58bc44151 transfer {"from":"0x5d4f08D5c2bb60703284bc06671Eb680fA41B105","to":"0x4F0E2D3477a1B94CF33d16E442CEe4733dadCeE7","value":"1200000"}
Prompt: Use Midjourney to generate one image of a futuristic cyberpunk city skyline at night, neon lights reflecting on wet streets, cinematic, 16:9 aspect ratio.
{ "_id": "8d2c17a9b26d4d83888ea67a1ee565b2", "type": "tts", "title": "Valentino Narración Biblica Fer", "description": "A mature and authoritative male voice with a calm, spiritual tone. It is well-suited for religious narration, educational content, and professional storytelling in Spanish.", "cover_image": "coverimage/8d2c17a9b26d4d83888ea67a1ee565b2", "train_mode": "fast", "state": "trained", "tags": [ "male", "old", "narration", "calm", "serious", "authoritative", "professional", "clear", "Spanish" ], "samples": [ { "title": "Default Sample", "text": "Hermanos míos, recordemos las palabras del Señor en estos tiempos difíciles. Como dice la Escritura, la fe mueve montañas, y el amor de Dios nos guía en cada paso del camino. Mantengamos firme nuestra confianza en Su divina providencia.", "task_id": "59ce7df6935c42249759327ddf70f37b", "audio": "https://c97f3361a1c971323738e24f451a0225.r2.cloudflarestorage.com/fish-platform-data/task/59ce7df6935c42249759327ddf70f37b.mp3?X-Amz-...signed..." } ], "created_at": "2025-03-13T08:11:10.326000Z", "updated_at": "2026-05-03T09:01:41.437000Z", "languages": ["es"], "visibility": "public", "lock_visibility": false, "dmca_taken_down": false, "default_text": "Hermanos míos, recordemos las palabras del Señor...", "quality": null, "like_count": 4344, "mark_count": 4409, "shared_count": 590, "task_count": 708461, "unliked": false, "liked": false, "marked": false, "author": { "_id": "1b82fb6a329c4462b67aa9ee0a42046f", "nickname": "Fernando Caicedo", "avatar": "avatars/1b82fb6a329c4462b67aa9ee0a42046f.jpg" } }
curl -X POST 'https://api.acedata.cloud/veo/extend' \ -H 'accept: application/json' \ -H 'authorization: Bearer {token}' \ -H 'content-type: application/json' \ -d '{ "video_id": "dd01fc69-e1f7-4b68-aa8c-463f6b748d11", "model": "veo31-fast", "prompt": "the camera slowly zooms out to reveal more of the landscape" }'