Tạo ảnh

Vẽ ảnh bằng API chuẩn OpenAI.

Endpoint duy nhất https://api.premiumshop.tech/v1/images/generations. Dùng model nào đang ACTIVE cũng được.

Thông tin dùng chung

Ba giá trị cần có trước mọi yêu cầu.

Endpoint tạo ảnh
https://api.premiumshop.tech/v1/images/generations
Endpoint sửa ảnh (img2img)
https://api.premiumshop.tech/v1/images/edits
API key
sk_shop_....<secret>
Model mẫu
claude-opus-5

Tạo ảnh mới (Text-to-Image)

Tạo ảnh bằng curlbash
curl https://api.premiumshop.tech/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk_shop_....<secret>" \
  -d '{"model":"claude-opus-5","prompt":"A tiny red apple on white background","size":"1024x1024"}'

Mỗi ảnh tốn khoảng 45.000 token (tính theo giá model bạn chọn). Ảnh trả về là base64 JPEG ~500–800KB.

Biến đổi ảnh (Image-to-Image / Edit)

Gửi kèm trường image chứa URL ảnh online hoặc chuỗi Data URI base64. Hỗ trợ cả POST /v1/images/edits và POST /v1/images/generations.

curl · img2img

curl · img2imgbash
curl https://api.premiumshop.tech/v1/images/edits \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk_shop_....<secret>" \
  -d '{
    "model": "claude-opus-5",
    "prompt": "Thêm chiếc mũ len màu đỏ cho chú chó trong ảnh",
    "image": "https://example.com/dog.jpg",
    "size": "1024x1024"
  }'

Python · img2img

Python · img2imgpython
import httpx
from openai import OpenAI
import base64

client = OpenAI(
    api_key="sk_shop_....<secret>",
    base_url="https://api.premiumshop.tech/v1",
    http_client=httpx.Client(trust_env=False),
)

# img2img: nhận URL trực tuyến hoặc chuỗi data:image/...;base64,...
res = client.post(
    "/images/edits",
    body={
        "model": "claude-opus-5",
        "prompt": "Thêm chiếc mũ len màu đỏ cho chú chó trong ảnh",
        "image": "https://example.com/dog.jpg",
        "size": "1024x1024",
    },
    cast_to=dict,
)

b64 = res["data"][0]["b64_json"]
with open("output.jpg", "wb") as f:
    f.write(base64.b64decode(b64))

Ví dụ SDK

Python

Python · OpenAI SDKpython
import httpx
from openai import OpenAI

client = OpenAI(
    api_key="sk_shop_....<secret>",
    base_url="https://api.premiumshop.tech/v1",
    http_client=httpx.Client(trust_env=False),
)

result = client.images.generate(
    model="claude-opus-5",
    prompt="A tiny red apple on white background",
    size="1024x1024",
)
b64 = result.data[0].b64_json
with open("output.jpg", "wb") as f:
    import base64
    f.write(base64.b64decode(b64))

Node.js

Node.js · OpenAI SDKtypescript
import OpenAI from "openai";
import { writeFileSync } from "node:fs";

const client = new OpenAI({
  apiKey: process.env.PREMIUMSHOP_API_KEY,
  baseURL: "https://api.premiumshop.tech/v1",
});

const result = await client.images.generate({
  model: "claude-opus-5",
  prompt: "A tiny red apple on white background",
  size: "1024x1024",
});

writeFileSync("output.jpg", Buffer.from(result.data[0].b64_json!, "base64"));

Tham số request

model

string, bắt buộc

Mã model bất kỳ đang ACTIVE (ví dụ claude-opus-5). Tính tiền theo giá model bạn chọn.

prompt

string, bắt buộc, tối đa 8.000 ký tự

Mô tả ảnh cần vẽ hoặc chỉnh sửa.

image

string, tùy chọn (img2img)

Ảnh gốc để chỉnh sửa / biến đổi. Hỗ trợ URL trực tuyến (https://...) hoặc Data URI base64 (data:image/png;base64,...).

size

string, tùy chọn

1024x1024 (mặc định, vuông 1:1) · 1024x1536 (dọc 2:3) · 1536x1024 (ngang 3:2).

n

number, tùy chọn

Luôn là 1 cho endpoint này.

response_format

string, tùy chọn

Luôn trả về b64_json (chuỗi base64 JPEG).

Model nào cũng vẽ được

Bạn có thể truyền bất kỳ model nào đang ACTIVE (claude-opus-5, cx/gpt-6-luna, dall-e-3, ...). Chất lượng và tốc độ (~10–20s/ảnh) như nhau với mọi model.

Tính tiền theo model bạn chọn

Quota và tiền tính theo giá model ghi trong request.

Kích thước & img2img

Hỗ trợ text-to-image và image-to-image. Nhận cả URL ảnh hoặc chuỗi base64.

Response

Trả về { created, data: [{ b64_json }] }. Giải base64 ra file .jpg là xem được. Không có URL tạm — hãy tự lưu ảnh.

Trang web chat (/app/chat) cũng hỗ trợ tạo ảnh: chuyển sang chế độ ảnh, nhập prompt và chọn model bất kỳ — ảnh hiện trực tiếp trong khung chat.