เอกสาร API สำหรับนักพัฒนา
RukPrompt API ให้คุณสร้างภาพด้วย AI จากแอปของคุณ ผ่าน HTTP request แบบ sync blocking (POST แล้วรอจน generate เสร็จ) โดยไม่ต้อง polling — เหมาะสำหรับ server-side integration, SDK, หรือ automation workflow
เริ่มใช้งาน API ฟรี
สมัคร workspace เพื่อสร้าง API key และเริ่ม generate ภาพ — ใช้เครดิตฟรีตั้งแต่สมัคร
https://developer.rukprompt.comBearer sk-img-...การยืนยันตัวตน (Authentication)
ทุก request ต้องมี header:
Authorization: Bearer sk-img-<your-key>
• สมัครสมาชิก เพื่อสร้าง workspace — ได้เครดิตฟรีตั้งแต่เริ่ม
• เข้าไปที่ Settings → สำหรับนักพัฒนา ในหน้า workspace เพื่อสร้าง API key
• key จะแสดงครั้งเดียวตอนสร้าง — บันทึกไว้ใน password manager หรือ environment variable
• เครดิตตัดจาก workspace ของ key — ดูยอดได้จาก GET /v0/usage
สร้างภาพด้วย AI
/v0/images/generationsสร้างภาพด้วย AI — รอสูงสุด 180 วินาที แล้วคืน URL ของภาพที่สร้างเสร็จทันที (sync blocking)
Example Request
curl -X POST https://developer.rukprompt.com/v0/images/generations \
-H "Authorization: Bearer sk-img-..." \
-H "Content-Type: application/json" \
-d '{
"prompt": "a cute cat wearing sunglasses",
"modelVersion": "gemini-2.5-flash-image",
"resolution": "standard",
"aspectRatio": "1:1",
"sampleCount": 1
}'Request Body Parametersคลิกช่องเพื่อแก้ค่า
promptstringpromptmodelVersionstringGET /v0/modelsmodelVersionGET /v0/modelsresolution"low" | "standard" | "high" | "4k""standard"resolution"standard"aspectRatiostring"1:1"aspectRatio"1:1"sampleCountinteger (1-4)1sampleCount1isPublicbooleanfalse• private (default): เห็นเฉพาะในทีมของคุณ
• public: โชว์ใน Community gallery — คนอื่นเห็นได้
isPublicfalse• private (default): เห็นเฉพาะในทีมของคุณ
• public: โชว์ใน Community gallery — คนอื่นเห็นได้
response_format"url" | "b64_json" | "both""url"•
url (default) คืนลิงก์ภาพ•
b64_json คืน base64 อย่างเดียว (เข้ากับ OpenAI)•
both คืนทั้ง url + base64ส่งเป็น query (
?response_format=b64_json) หรือใน body ก็ได้response_format"url"•
url (default) คืนลิงก์ภาพ•
b64_json คืน base64 อย่างเดียว (เข้ากับ OpenAI)•
both คืนทั้ง url + base64ส่งเป็น query (
?response_format=b64_json) หรือใน body ก็ได้asyncbooleanfalsetrue — enqueue แล้ว return jobId ทันที (ไม่รอ) แล้วให้ poll ผ่าน GET /v0/images/generations/{jobId}แนะนำสำหรับโมเดลที่ช้า (gpt-image-2 อาจเกิน 180s) หรืออยู่หลัง proxy ที่มี timeout สั้น
asyncfalsetrue — enqueue แล้ว return jobId ทันที (ไม่รอ) แล้วให้ poll ผ่าน GET /v0/images/generations/{jobId}แนะนำสำหรับโมเดลที่ช้า (gpt-image-2 อาจเกิน 180s) หรืออยู่หลัง proxy ที่มี timeout สั้น
negativePromptstringnegativePromptpresetIdstringpresetIdvariablesobjectvariablesrefImageUrlsstring[]refImageUrlsrefImageBase64{ mimeType, data }[]refImageBase64Response (200 OK)
{
"code": 200,
"data": {
"id": "job_abc123", // jobId สำหรับ tracking
"created": 1745000000, // unix timestamp
"model": "gemini-2.5-flash-image",
"data": [
{
"id": "img_xyz", // generated image id
"url": "https://cdn.rukprompt.com/teams/.../abc.png",
"storageKey": "teams/.../abc.png",
// ถ้าส่ง ?response_format=b64_json หรือ both จะมี field เพิ่ม:
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA...",
"mimeType": "image/png"
}
],
"usage": {
"credits": 1 // เครดิตที่ถูกตัดจาก team
}
}
}ตรวจสอบสถานะ Job
/v0/images/generations/:jobIdใช้เมื่อ POST ได้ 504 timeout เพื่อเช็คว่า job เสร็จหรือยัง — คืนข้อมูลภาพเมื่อ status = completed
curl "https://developer.rukprompt.com/v0/images/generations/job_abc123" \ -H "Authorization: Bearer sk-img-..."
POST /v0/images/generationsแต่จะมี status field เพิ่ม:"waiting" | "processing" | "completed" | "failed"รายการ AI Models ที่ใช้ได้
/v0/modelsดูโมเดลทั้งหมด + ค่าเครดิตต่อภาพ + aspect ratios ที่แต่ละโมเดลรองรับ
curl "https://developer.rukprompt.com/v0/models" \ -H "Authorization: Bearer sk-img-..."
Models ที่ใช้งานได้ในทีมของคุณ
ตัวเลขคือเครดิตต่อ 1 ภาพ — ถ้า sampleCount = 4 จะคูณ 4
Presets (CRUD)
/v0/images/presetsจัดการ preset ของทีมผ่าน API key — สร้าง / แก้ไข / ลบ / ดู ได้เต็ม. AI agent (เช่น MCP) ก็เรียกชุดนี้เพื่อสร้าง preset อัตโนมัติได้
1. List presets
curl "https://developer.rukprompt.com/v0/images/presets" \ -H "Authorization: Bearer sk-img-..."
เพิ่ม ?teamOnly=true ใน URL ถ้าอยากได้เฉพาะ preset ของทีม (ไม่รวม public)
2. Get one preset
curl "https://developer.rukprompt.com/v0/images/presets/<presetId>" \ -H "Authorization: Bearer sk-img-..."
3. Create preset (POST)
prompt ใช้ {{key}} placeholder ทุก {{key}} ต้องมี matching item ใน requirements. key ต้องเป็น snake_case ภาษาอังกฤษ. ใช้ {{#if key}}...{{/if}} สำหรับตัวแปร optional.
curl -X POST "https://developer.rukprompt.com/v0/images/presets" \
-H "Authorization: Bearer sk-img-..." \
-H "Content-Type: application/json" \
-d '{
"name": "Product Photography",
"note": "ภาพโฆษณาสินค้าสไตล์ studio",
"prompt": "ภาพถ่ายโฆษณาสินค้า {{product_name}} สำหรับกลุ่มเป้าหมาย {{target_audience}} สไตล์ {{art_style}}{{#if extra_note}}, {{extra_note}}{{/if}} คุณภาพสูง รายละเอียดชัดเจน",
"requirements": [
{
"key": "product_name",
"label": "ชื่อสินค้า",
"type": "text",
"required": true,
"placeholder": "เช่น รองเท้าวิ่ง Nike Air Max"
},
{
"key": "target_audience",
"label": "กลุ่มเป้าหมาย",
"type": "dropdown",
"required": false,
"defaultValue": "adults aged 25-45",
"options": [
{
"label": "วัยรุ่น",
"value": "teenagers aged 15-25"
},
{
"label": "ผู้ใหญ่",
"value": "adults aged 25-45"
},
{
"label": "ผู้สูงอายุ",
"value": "seniors aged 50+"
}
]
},
{
"key": "art_style",
"label": "สไตล์ภาพ",
"type": "text",
"defaultValue": "minimalist"
},
{
"key": "extra_note",
"label": "หมายเหตุเพิ่มเติม",
"type": "text",
"required": false
}
],
"modelVersion": "gemini-2.5-flash-image",
"lockModel": true,
"defaultAspectRatio": "1:1",
"tags": [
"product",
"studio",
"advertising"
]
}'4. Update preset (PATCH)
ส่งเฉพาะ field ที่ต้องการแก้ — version snapshot จะถูกสร้างอัตโนมัติทุกครั้งที่ update
curl -X PATCH "https://developer.rukprompt.com/v0/images/presets/<presetId>" \
-H "Authorization: Bearer sk-img-..." \
-H "Content-Type: application/json" \
-d '{
"name": "Product Photography v2",
"note": "ปรับ prompt ให้เน้น dramatic lighting",
"prompt": "ภาพถ่ายโฆษณาสินค้า {{product_name}} สไตล์ {{art_style}} แสง dramatic studio lighting{{#if extra_note}}, {{extra_note}}{{/if}}",
"tags": [
"product",
"dramatic"
]
}'5. Delete preset (DELETE)
curl -X DELETE "https://developer.rukprompt.com/v0/images/presets/<presetId>" \ -H "Authorization: Bearer sk-img-..."
6. Use preset to generate
ส่ง presetId + variables เข้า /v0/images/generations
{
"presetId": "<presetId>",
"prompt": "",
"variables": {
"product_name": "Nike Air Zoom Pegasus",
"target_audience": "adults aged 25-45",
"art_style": "cinematic",
"extra_note": "with motion blur effect"
},
"aspectRatio": "1:1",
"sampleCount": 1
}Response (สำหรับ POST / PATCH / GET single)
{
"data": {
"id": "preset_abc123",
"name": "Product Photography",
"note": "ภาพโฆษณาสินค้าสไตล์ studio",
"modelVersion": "gemini-2.5-flash-image",
"defaultAspectRatio": "1:1",
"lockModel": true,
"lockAspectRatio": false,
"thumbnailUrl": null,
"requirements": [
{ "key": "product_name", "label": "ชื่อสินค้า", "type": "text", "required": true },
{ "key": "target_audience", "label": "กลุ่มเป้าหมาย", "type": "dropdown",
"options": [
{ "label": "ผู้ใหญ่", "value": "adults aged 25-45" }
]
}
],
"accessLevel": "FULL",
"isCommunity": false,
"categories": [],
"originTeam": null,
"createdAt": "2026-04-26T..."
}
}Note: response จะ ไม่ echo prompt template — เพื่อกัน leak template ระหว่างทีม
Reference เต็ม: /v0/developer-docs/presets (markdown ที่ AI scrape ได้ตรงๆ)
รายการรูปที่สร้างเสร็จ (List)
/v0/images/libraryดึงรายการรูปทั้งหมดของทีม — paginated, กรองตาม preset หรือค้นหาจาก userPrompt ได้
curl "https://developer.rukprompt.com/v0/images/library?page=1&limit=20" \ -H "Authorization: Bearer sk-img-..."
Query params (ทุกตัว optional):
page— เลขหน้า (default 1)limit— จำนวนต่อหน้า 1–100 (default 20)presetId— กรองเฉพาะรูปที่สร้างจาก preset นี้search— ค้นหาจาก userPrompt + ชื่อ preset
Response
{
"data": {
"images": [
{
"id": "img_abc123",
"url": "https://cdn.../image.webp",
"thumbnailUrl": "https://cdn.../thumb.webp",
"width": 1024,
"height": 1024,
"presetId": "preset_xyz",
"modelVersion": "gemini-2.5-flash-image",
"userPrompt": "ภาพถ่ายรองเท้าวิ่ง",
"isPublic": false,
"createdAt": "2026-04-26T..."
}
],
"total": 124,
"page": 1,
"limit": 20
}
}รายละเอียดรูป (Get One)
/v0/images/library/:imageIdดึง metadata + URL ของรูป 1 ใบ — ใช้เมื่อรู้ imageId แล้ว (เช่นจาก /generations response)
curl "https://developer.rukprompt.com/v0/images/library/<imageId>" \ -H "Authorization: Bearer sk-img-..."
Response
{
"data": {
"id": "img_abc123",
"presetId": "preset_xyz",
"prompt": "rendered prompt with variables filled in",
"userPrompt": "ภาพถ่ายรองเท้าวิ่ง",
"modelVersion": "gemini-2.5-flash-image",
"variables": { "product_name": "Nike Air Zoom" },
"sourceType": null,
"isPublic": false,
"url": "https://cdn.../image.webp",
"thumbnailUrl": "https://cdn.../thumb.webp",
"width": 1024,
"height": 1024,
"createdAt": "2026-04-26T..."
}
}ดาวน์โหลดรูป (Binary)
/v0/images/library/:imageId/downloadดาวน์โหลดไฟล์ binary โดยตรง — response เป็น Content-Disposition: attachment พร้อม filename
curl "https://developer.rukprompt.com/v0/images/library/<imageId>/download" \ -H "Authorization: Bearer sk-img-..." \ -o image.webp
Tip: ส่วนใหญ่ไม่ต้อง download เลย — ใช้ url จาก /library/:id ตรงๆ ก็ได้ (R2 public URL) เร็วกว่าและไม่ใช้ quota dev API
Endpoint นี้เหมาะกับกรณีที่ต้องการ bytes ใน server เช่นใส่ใน ZIP / re-upload ไป third party
MCP Server (สำหรับ AI Agent)
/v0/mcpModel Context Protocol — Claude Desktop / Cursor / MCP client เชื่อมตรงเข้ามาได้ ใช้ API key เดิม sk-img-...
MCP wraps endpoint ทั้งหมดข้างต้นเป็น 11 tools ที่ AI agent เรียกได้:
Presets: preset_list / preset_get / preset_create / preset_update / preset_delete
Images: image_generate / image_list / image_get / image_download
Models: model_list
Credits: credits_check (เช็คเครดิตคงเหลือก่อน generate)
✨ Recommended: ใช้ CLI (npx)
One command — install + ตั้ง key + เขียน config block ลง MCP client ทำให้พร้อมใช้งานเลย เลือก client ด้านล่างเพื่อให้คำสั่งอัปเดตให้ตรง
npx -y @rukprompt/cli install claude-desktop --api-key sk-img-...
📝 Manual config (npx)
ถ้าอยาก paste config block เอง — ใช้ shape เดียวกันทุก client (Claude Desktop / Claude Code / Cursor)
{
"mcpServers": {
"rukprompt": {
"command": "npx",
"args": ["-y", "@rukprompt/cli", "mcp"],
"env": { "RUKPROMPT_API_KEY": "sk-img-..." }
}
}
}Direct CLI (terminal usage)
CLI มี sub-command ตรงกับ MCP tool — ใช้ใน terminal โดยไม่ต้องผ่าน MCP client เลย
# Presets
rukprompt preset list --team-only
rukprompt preset create --name "Studio shot" --prompt "minimal product photo of {{product}}"
# Images
rukprompt image generate --prompt "a cat astronaut" --aspect 16:9 --out cat.png
rukprompt image list --limit 50
# Models / credits
rukprompt model list
rukprompt credits checkKey management
rukprompt key set --api-key sk-img-... # validate + persist rukprompt key show # show masked key + last validated rukprompt key test # ping backend rukprompt key clear # remove from this machine
🔧 Advanced: Direct HTTP (base layer)
CLI เป็น proxy layer ที่ wrap HTTP MCP ที่ https://developer.rukprompt.com/v0/mcp. ถ้าอยาก connect ตรงๆ (เช่น runtime ที่ไม่มี Node.js) ก็ทำได้:
{
"mcpServers": {
"rukprompt": {
"type": "http",
"url": "https://developer.rukprompt.com/v0/mcp",
"headers": { "Authorization": "Bearer sk-img-..." }
}
}
}หมายเหตุ: ต้องมี "type": "http" สำหรับ Claude Code CLI (~/.claude.json) — ไม่งั้นจะเจอ error "Does not adhere to MCP server configuration schema"
Raw JSON-RPC (curl)
curl -X POST https://developer.rukprompt.com/v0/mcp \
-H "Authorization: Bearer sk-img-..." \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'MCP Inspector
# ผ่าน CLI (stdio): npx @modelcontextprotocol/inspector \ --command "npx -y @rukprompt/cli mcp" \ --env "RUKPROMPT_API_KEY=sk-img-..." # หรือ direct HTTP: npx @modelcontextprotocol/inspector \ --url https://developer.rukprompt.com/v0/mcp \ --header "Authorization: Bearer sk-img-..."
Reference เต็ม: /v0/developer-docs/mcp
ทุก tool call ของ MCP ถูก log ใน developer_api_usage เหมือน REST request
API Reference (สำหรับ AI / Developer)
/v0/developer-docsMarkdown reference ที่ AI scrape อ่านได้โดยตรง + OpenAPI 3.0 spec ที่ generate client หรือ introspect ได้
Markdown Reference (text/markdown)
- Getting Started — auth, base URL, endpoint map
- Presets — schema, requirement types, conditional blocks, ตัวอย่าง CRUD
- Image Generation — sync vs async, multipart, aspect ratios
- Errors — รายการ HTTP code + retry policy
- MCP Setup — Claude Desktop / Cursor config
OpenAPI 3.0 Spec
สำหรับ generate client ภาษาต่างๆ หรือใช้ใน Swagger UI / Postman / Insomnia:
# Download OpenAPI spec (JSON) curl https://developer.rukprompt.com/docs/developer.json > developer-api.json # Generate TypeScript client (เช่น openapi-typescript) npx openapi-typescript https://developer.rukprompt.com/docs/developer.json -o ./api-types.ts
เครดิตคงเหลือและประวัติการใช้
/v0/usageเครดิตคงเหลือของทีม + สถิติการใช้งาน + 50 jobs ล่าสุด
curl "https://developer.rukprompt.com/v0/usage?from=2026-04-01&to=2026-04-30" \ -H "Authorization: Bearer sk-img-..."
Query params (optional):
from— ISO date (start of range)to— ISO date (end of range)
ประวัติการเรียก API
/v0/historyประวัติการเรียก API ทั้งหมดของทีม — กรองและแบ่งหน้าได้
curl "https://developer.rukprompt.com/v0/history?page=1&limit=20&status=success" \ -H "Authorization: Bearer sk-img-..."
Query params:
page— default 1limit— 1-100, default 20status— "success" | "failed"apiKeyId— filter เฉพาะ keyfrom/to— ISO date range
รหัส Error (Error Codes)
{
"code": 401,
"message": "Invalid or revoked API key",
"data": null
}