昨日の今日で早くもクレジット登録する日が来てしまったかもしれない?

クレジットカード登録無しで Chat Completion API を使うことができたので、
あれれ?となっていましたが・・・
Image Generation API を使ってみると・・・?
- Chat Completion API
- Image Generation API
- Quick Start
- リミットの確認
- Developer Forum の確認
- 画像について問い合わせをしてみる
- まとめ
Chat Completion API
https://platform.openai.com/docs/api-reference/chat
Image Generation API
https://platform.openai.com/docs/api-reference/images
Quick Start
https://platform.openai.com/docs/quickstart
from openai import OpenAI
client = OpenAI(api_key='<API_KEY>')
response = client.images.generate(
prompt="A cute baby sea otter",
n=2,
size="1024x1024"
)
print(response.data[0].url)
実行結果
$ python generate_images.py
Traceback (most recent call last):
~省略~
openai.BadRequestError: Error code: 400 - {'error': {'code': 'billing_hard_limit_reached', 'message': 'Billing hard limit has been reached', 'param': None, 'type': 'invalid_request_error'}}
Billing hard limit has been reached というエラーになりました。
クレジット残高が $0.00 だからですかね??
リミットの確認

DALL-E-2 であれば 5 img / min
DALL-E-3 であれば 1 img / min
ということで、なんか Free tier でも生成できそうな気がしますけどね。
Free tier から Tier 1 へ昇格するためには「有料アカウントへの移行」及び「$5 の消費」があるので、とりあえずクレジット残高を増やさないと Free tier でも使えないよ。ってことなんでしょうか?
Developer Forum の確認
「有料アカウントへ移行」「クレジット残高の追加」等で解決したという方も居れば、
解決できなかったよ。って方も居そうな雰囲気ですね。
画像について問い合わせをしてみる
from openai import OpenAI
client = OpenAI(api_key='<API_KEY>')
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
},
},
],
}
],
max_tokens=300,
)
print(response.choices[0])
これ自体は Chat Completion API の「テキストではなく画像版」という感じですが、
これは問題なく実行可能でした。 Image Generation API の方だけが使えないんですかねぇ?
実行結果
$ python vision.py Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='The image features a wooden pathway that extends through a wide, grassy area. On either side of the path, there are lush green grasses and some shrubbery, under a blue sky filled with soft clouds. The scene conveys a tranquil, natural landscape, suggesting a peaceful outdoor environment, possibly a wetland or nature reserve.', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))
この画像には、広い草地に伸びる木の小道が描かれています。小道の両側には、柔らかい雲が浮かぶ青い空の下に、青々とした緑の草と低木が生えています。このシーンは、静かで自然な風景を伝えており、湿地や自然保護区などの穏やかな屋外環境を示唆しています。