~$0.0696
 1import requests
 2import time
 3import json
 4
 5api_key = "YOUR_API_KEY"
 6url = "https://api.segmind.com/workflows/66d6ac02f56156a63306b887-v2"
 7
 8data = {
 9    "input_image": "https://segmind-inference-inputs.s3.amazonaws.com/fd9e41ac-e926-4a7e-bbc6-d9618c857aac-456447860_1039460734453026_4842210575810694885_n.jpg",
10    "reference_image": "https://segmind-inference-inputs.s3.amazonaws.com/94c3f217-7c8e-4f36-a6d2-a11ff2e6895c-Beetroot-Burger.jpg",
11    "text_prompt": "A close-up of a large, juicy burger with a sesame seed bun, resting on a wooden cutting board. The background is a dark, blurred color, which contrasts with the vibrant colors of the burger, making it the focal point of the image.",
12    "select_food_item": "burger"
13}
14
15def poll_for_result(poll_url):
16    """Poll the API until the generation is complete"""
17    while True:
18        response = requests.get(
19            poll_url,
20            headers={'Authorization': f'Bearer {api_key}'}
21        )
22        result = response.json()
23
24        if result['status'] == 'COMPLETED':
25            # Parse the output (it's a JSON string)
26            outputs = json.loads(result['output'])
27            return outputs
28        elif result['status'] == 'FAILED':
29            raise Exception(result.get('error', 'Generation failed'))
30
31        # Wait 7 seconds before polling again
32        time.sleep(7)
33
34# Make the initial request
35response = requests.post(
36    url,
37    json=data,
38    headers={
39        'Authorization': f'Bearer {api_key}',
40        'Content-Type': 'application/json'
41    }
42)
43
44if response.status_code == 200:
45    result = response.json()
46    print('Request queued:', result)
47
48    # Start polling for results
49    outputs = poll_for_result(result['poll_url'])
50    print('Generation complete:', outputs)
51else:
52    print(f"Error: {response.status_code}")
53    print(response.text)

API Endpoint

POSThttps://api.segmind.com/workflows/66d6ac02f56156a63306b887-v2

Parameters

input_imageoptional
string (uri)

Input Image

Default: "https://segmind-inference-inputs.s3.amazonaws.com/fd9e41ac-e926-4a7e-bbc6-d9618c857aac-456447860_1039460734453026_4842210575810694885_n.jpg"
reference_imageoptional
string (uri)

Reference Image

Default: "https://segmind-inference-inputs.s3.amazonaws.com/94c3f217-7c8e-4f36-a6d2-a11ff2e6895c-Beetroot-Burger.jpg"
text_promptoptional
string

Text Prompt

Default: "A close-up of a large, juicy burger with a sesame seed bun, resting on a wooden cutting board. The background is a dark, blurred color, which contrasts with the vibrant colors of the burger, making it the focal point of the image."
select_food_itemoptional
string

Select Food Item

Default: "burger"

Response Format

Returns: Polling-based asynchronous response

Initial request returns a poll_url. Poll every 7 seconds until status is COMPLETED.

Common Error Codes

The API returns standard HTTP status codes. Detailed error messages are provided in the response body.

400

Bad Request

Invalid parameters or request format

401

Unauthorized

Missing or invalid API key

403

Forbidden

Insufficient permissions

404

Not Found

Workflow not found

406

Insufficient Credits

Not enough credits to process request

429

Rate Limited

Too many requests

500

Server Error

Internal server error

502

Bad Gateway

Service temporarily unavailable

504

Timeout

Request timed out