인기 모델
1단계: 이미지 업로드 또는 참조
먼저 원본 이미지를 제공해야 합니다. 다음 중 하나의 방법을 사용할 수 있습니다.- 이미지 파일을 base64 데이터 URI로 업로드
- 공개적으로 접근 가능한 이미지 URL 제공
import { readFileSync } from "node:fs";
// Option 1: Using a base64 data URI
const imageBuffer = readFileSync("input_image.jpg");
const imageDataUri = `data:image/jpeg;base64,${imageBuffer.toString("base64")}`;
// Option 2: Using image URL
const imageUrl = "https://s.krea.ai/logo-icon-black.jpg";
import requests
import base64
API_BASE = "https://api.krea.ai"
API_TOKEN = "YOUR_API_TOKEN"
# Option 1: Using a base64 data URI
with open("input_image.jpg", "rb") as image_file:
image_data_uri = f"data:image/jpeg;base64,{base64.b64encode(image_file.read()).decode('utf-8')}"
# Option 2: Using image URL
image_url = "https://s.krea.ai/logo-icon-black.jpg"
API 토큰으로 교체하세요위 예제에서 YOUR_API_TOKEN 자리표시자를 교체하려면 krea.ai/settings/api-tokens에서 API 토큰을 생성해야 합니다. 도움이 필요하면 API 키 및 결제 페이지의 안내를 따르세요.
2단계: 이미지 생성
이미지와 매개변수를 포함하여 해당 엔드포인트로 POST 요청을 보냅니다.// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";
const krea = new Krea({ apiKey: process.env.KREA_API_KEY });
const job = await krea.image("google/nano-banana-pro", {
image_urls: [imageDataUri],
prompt: "Turn this logo into an aesthetic rug. Product Photography style, with an aura that would make me want it in my own living room."
});
console.log(`Job ID: ${job.job_id}`);
IMAGE_DATA_URI="data:image/jpeg;base64,$(base64 < ./input_image.jpg | tr -d '\n')"
curl -X POST https://api.krea.ai/generate/image/google/nano-banana-pro \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"image_urls": ["'"$IMAGE_DATA_URI"'"],
"prompt": "Turn this logo into an aesthetic rug. Product Photography style, with an aura that would make me want it in my own living room."
}'
response = requests.post(
f"{API_BASE}/generate/image/google/nano-banana-pro",
headers={
"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"
},
json={
"image_urls": [image_data_uri],
"prompt": "Turn this logo into an aesthetic rug. Product Photography style, with an aura that would make me want it in my own living room.",
}
)
job = response.json()
print(f"Job ID: {job['job_id']}")
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
apiBase := "https://api.krea.ai"
apiToken := "YOUR_API_TOKEN"
imageBytes, _ := os.ReadFile("input_image.jpg")
imageDataURI := "data:image/jpeg;base64," + base64.StdEncoding.EncodeToString(imageBytes)
payload := map[string]interface{}{
"image_urls": []interface{}{imageDataURI},
"prompt": "Turn this logo into an aesthetic rug. Product Photography style, with an aura that would make me want it in my own living room.",
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", apiBase+"/generate/image/google/nano-banana-pro", bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer "+apiToken)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
var job map[string]interface{}
json.NewDecoder(resp.Body).Decode(&job)
fmt.Printf("Job ID: %s\n", job["job_id"])
}
{
"created_at":"2026-02-13T02:20:58.265Z",
"completed_at":null,
"job_id":"757a315b-b3ed-457b-b1ba-cff5e140cfd4",
"status":"processing",
"type":"externalImage",
"result":{}
}
3단계: 결과 폴링
이미지 생성은 비동기 방식입니다. 즉시 작업 ID를 받고, 이미지가 준비될 때까지 결과를 폴링합니다. 작업이 완료될 때까지 2초마다/jobs/{job_id}를 폴링하세요.
// npm install @krea-ai/sdk
import { Krea } from "@krea-ai/sdk";
const krea = new Krea({ apiKey: process.env.KREA_API_KEY });
async function waitForJob(jobId) {
const completed = await krea.jobs.wait(jobId, { intervalMs: 2000 });
return completed.result.urls[0];
}
const imageUrl = await waitForJob(job.job_id);
console.log(`Image ready: ${imageUrl}`);
curl -X GET https://api.krea.ai/jobs/YOUR_JOB_ID \
-H "Authorization: Bearer YOUR_API_TOKEN"
import time
def wait_for_job(job_id):
while True:
response = requests.get(
f"{API_BASE}/jobs/{job_id}",
headers={"Authorization": f"Bearer {API_TOKEN}"}
)
job = response.json()
if job["status"] == "completed":
return job["result"]["urls"][0]
if job["status"] in ("failed", "cancelled"):
raise Exception(f"Job failed: {job['status']}")
print(f"Status: {job['status']}")
time.sleep(2)
image_url = wait_for_job(job["job_id"])
print(f"Image ready: {image_url}")
func waitForJob(jobID string) (string, error) {
for {
req, _ := http.NewRequest("GET", apiBase+"/jobs/"+jobID, nil)
req.Header.Set("Authorization", "Bearer "+apiToken)
resp, _ := client.Do(req)
var job map[string]interface{}
json.NewDecoder(resp.Body).Decode(&job)
resp.Body.Close()
switch job["status"] {
case "completed":
result := job["result"].(map[string]interface{})
urls := result["urls"].([]interface{})
return urls[0].(string), nil
case "failed", "cancelled":
return "", fmt.Errorf("job failed: %s", job["status"])
}
fmt.Printf("Status: %s\n", job["status"])
time.Sleep(2 * time.Second)
}
}
{
"created_at":"2026-02-13T02:20:58.265Z",
"completed_at":"2026-02-13T02:21:21.948Z",
"job_id":"757a315b-b3ed-457b-b1ba-cff5e140cfd4",
"status":"completed",
"type":"externalImage",
"result": {
"urls": [
"https://app-uploads.krea.ai/public/757a315b-b3ed-457b-b1ba-cff5e140cfd4-image.png"
]
}
}
웹훅을 사용할 수 있습니다!작업이 완료되면 알림을 받도록 웹훅을 설정하세요. 시작하려면 웹훅 가이드를 참조하세요.