17
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenAI の新しい画像生成API(gpt-image-1)を試してみた

Last updated at Posted at 2025-04-23

朝、4時に目を覚ますとOpenAIという謎のAI会社が画像作るAPIを出してたので試してみました。

image.png

↓↓説明

ガイド

image.png
俺たちにできないことを平然とやってのける。そこに痺れる。憧れる。

要点

  • gpt-image-1は で 「画像のChatGPT」 といえる存在
  • APIから使えるようになったのは商用にも大きい
  • 安全対策も万全(Moderationパラメータで調整可)

認証が必要(個人情報登録)

なんか、オーガナイゼーション認証が必要でした。犯罪に使われるからでしょうか?

とりあえず、マイナンバーカードでサクッと登録、個人情報を紐づけます。顔面の写真も撮られます。
いわゆる eKYCですね。

使い方

あとは、PlayGroundでプロンプト適当に入れると絵が生成されます。

image.png

image.png

PlayGroundだとNSFWっぽいのプロンプトはすぐ怒られます。

image.png

多分コンテンツ モデレーション(moderation)パラメータで倫理観をlowで落とせばOK?

image.png

API

APIはこんな感じ

Python

from openai import OpenAI
client = OpenAI()

response = client.images.generate(
  model="gpt-image-1",
  prompt="anime-style illustration of a magical girl version of a 22-year-old Japanese female college student, long blonde twintails, wearing a sparkly pink and gold magical costume with ribbons, thigh-high boots, holding a glowing wand, on a starry stage with spotlight, cute and confident pose, 7000K lighting, vivid colors, anime background  \n",
  n=1,
  size="1024x1536",
  quality="high"
)

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

const response = await openai.images.generate({
  model: "gpt-image-1",
  prompt: "anime-style illustration of a magical girl version of a 22-year-old Japanese female college student, long blonde twintails, wearing a sparkly pink and gold magical costume with ribbons, thigh-high boots, holding a glowing wand, on a starry stage with spotlight, cute and confident pose, 7000K lighting, vivid colors, anime background  \n",
  n: 1,
  size: "1024x1536",
  quality: "high"
});

JSON

{
  "model": "gpt-image-1",
  "prompt": "anime-style illustration of a magical girl version of a 22-year-old Japanese female college student, long blonde twintails, wearing a sparkly pink and gold magical costume with ribbons, thigh-high boots, holding a glowing wand, on a starry stage with spotlight, cute and confident pose, 7000K lighting, vivid colors, anime background  \n",
  "n": 1,
  "size": "1024x1536",
  "quality": "high"
}

Curl

curl https://api.openai.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
  "model": "gpt-image-1",
  "prompt": "anime-style illustration of a magical girl version of a 22-year-old Japanese female college student, long blonde twintails, wearing a sparkly pink and gold magical costume with ribbons, thigh-high boots, holding a glowing wand, on a starry stage with spotlight, cute and confident pose, 7000K lighting, vivid colors, anime background  \n",
  "n": 1,
  "size": "1024x1536",
  "quality": "high"
}' | jq -r '.data[0].b64_json' | base64 --decode > output.png

実際に API 使ってみた

普通に Curl

image.png

image.png

透過PNGを出す

"background": "transparent"

image.png

iTerm2.Zi2dWR.png

コスト

結構高いw

image.png

最後に

image.png

AI情報発信してます!(1日二十円で読める
↓↓↓

17
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?