Image Generation API
Generate high-quality images from text descriptions using our advanced AI models. This endpoint allows you to create custom images based on detailed prompts.
Token Usage
This endpoint consumes tokens from your token balance based on the complexity of the prompt and the generated image.
Learn more about billingEndpoint Details
Endpoint
POST /api/images/generate
Headers
Content-Type: application/json
X-API-Key: your_api_key_here
Request Body
{
"prompt": "A detailed description of the image you want to generate"
}
Parameter | Type | Required | Description |
---|---|---|---|
prompt | string | Yes | A detailed description of the image you want to generate. |
Success Response (200 OK)
{
"id": "image-id",
"prompt": "A detailed description of the image you want to generate",
"imageUrl": "https://storage.amazonaws.com/bucket-name/images/user_id/generated-image.jpg",
"createdAt": "2023-06-15T10:30:00Z",
"sessionId": "session-id",
"tokensUsed": 500
}
Field Descriptions
Field Path | Type | Description |
---|---|---|
id | string | Unique identifier for the generated image. |
prompt | string | The original prompt used to generate the image. |
imageUrl | string | Public URL of the generated image. |
createdAt | string | Timestamp when the image was generated (ISO 8601). |
sessionId | string | Session identifier for related image generations. |
tokensUsed | number | Number of tokens consumed by this operation. |
Error Responses
Example error for invalid input:
{
"error": "Invalid prompt format" // Example error
}
Refer to the Error Handling section for details on other potential errors.
Available Endpoints
Generate Image
Create a new image from a text description.
Edit Image
Modify an existing image using a text description of desired changes.
Endpoint
POST /api/images/edit-with-url
Request Body
{
"imageUrl": "URL of the image to edit",
"prompt": "A detailed description of the changes you want to make",
"sessionId": "session-id"
}
Parameter | Type | Required | Description |
---|---|---|---|
imageUrl | string | Yes | URL of the image to edit |
prompt | string | Yes | Description of the desired changes |
sessionId | string | Yes | Session ID for tracking related edits |
Response
{
"id": "edited-image-id",
"originalImageUrl": "URL of the original image",
"editedImageUrl": "https://storage.amazonaws.com/bucket-name/images/user_id/edited-image.jpg",
"prompt": "A detailed description of the changes you want to make",
"createdAt": "2023-06-15T10:30:00Z",
"sessionId": "session-id",
"tokensUsed": 600
}
Session Management
Manage image generation sessions and track related operations.
Start Session
POST /api/images/sessions
Request Body:
{
"key": "images/user_id/initial-image.jpg"
}
Response:
{
"sessionId": "session-id",
"initialImageUrl": "https://storage.amazonaws.com/bucket-name/images/user_id/initial-image.jpg",
"createdAt": "2023-06-15T10:30:00Z"
}
Get Session History
GET /api/images/sessions/:sessionId
Response:
{
"sessionId": "session-id",
"initialImageUrl": "https://storage.amazonaws.com/bucket-name/images/user_id/initial-image.jpg",
"createdAt": "2023-06-15T10:30:00Z",
"images": [
{
"id": "image-id-1",
"imageUrl": "https://storage.amazonaws.com/bucket-name/images/user_id/generated-image-1.jpg",
"prompt": "Original prompt",
"createdAt": "2023-06-15T10:35:00Z"
},
{
"id": "image-id-2",
"imageUrl": "https://storage.amazonaws.com/bucket-name/images/user_id/generated-image-2.jpg",
"prompt": "Modified prompt",
"createdAt": "2023-06-15T10:40:00Z"
}
]
}
Get Generation History
GET /api/images/generations/history
Response:
{
"sessions": [
{
"sessionId": "session-id-1",
"initialImageUrl": "https://storage.amazonaws.com/bucket-name/images/user_id/initial-image-1.jpg",
"createdAt": "2023-06-15T10:30:00Z",
"lastModified": "2023-06-15T11:30:00Z",
"imageCount": 5
},
{
"sessionId": "session-id-2",
"initialImageUrl": "https://storage.amazonaws.com/bucket-name/images/user_id/initial-image-2.jpg",
"createdAt": "2023-06-16T14:20:00Z",
"lastModified": "2023-06-16T15:20:00Z",
"imageCount": 3
}
]
}
Code Examples
Use the following examples to integrate the Image Generation API.
curl -X POST https://your-api-domain.com/api/images/generate \
-H "Content-Type: application/json" \
-H "X-API-Key: your_api_key_here" \
-d '{
"prompt": "A detailed description of the image you want to generate"
}'
Prompt Guidelines
For best results, provide detailed and specific prompts that describe the desired image. Include information about style, composition, lighting, and other relevant details. The more specific your prompt, the better the generated image will match your vision.