Text-to-Image Generation
Feature Description
Text-to-image models can generate corresponding images based on text descriptions input by users. These models support various styles and themes, capable of producing high-quality images suitable for multiple fields such as creative design and artistic creation.

Although they are all text-to-image models, different models may have inconsistent calling parameters. For specific parameters and their meanings, please refer to the experience interface of the corresponding model.
Text-to-Image Model List
MoArk provides a rich selection of text-to-image models. You can view and experience these models in the Model Square.
Loading Serverless API service list...
Calling Text-to-Image Models
Using OpenAI SDK
You can use the OpenAI SDK to call text-to-image models. Here is an example using Python:
from openai import OpenAI
import base64
client = OpenAI(
base_url="https://moark.ai/v1",
api_key="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", # Replace with your access token
default_headers={"X-Failover-Enabled":"true"},
)
response = client.images.generate(
prompt="a white siamese cat", # Replace with your text description
model="Kolors", # Replace with your selected model name
size="1024x1024",
extra_body={
"num_inference_steps": 25,
"guidance_scale": 7.5,
},
)
image_base64 = response.data[0].b64_json
image_bytes = base64.b64decode(image_base64)
# Save the image to a file
with open("Kolors-output.png", "wb") as f:
f.write(image_bytes)
Using Requests Library
If you prefer not to use the OpenAI SDK, you can directly use the requests library to call text-to-image models. Here's a Python example:
import requests
import base64
import json
url = "https://moark.ai/v1/images/generations"
headers = {
"Authorization": "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", # Replace with your access token
"Content-Type": "application/json",
"X-Failover-Enabled": "true"
}
data = {
"prompt": "a white siamese cat", # Replace with your text description
"model": "Kolors", # Replace with your selected model name
"size": "1024x1024",
"response_format": "b64_json",
"num_inference_steps": 25,
"guidance_scale": 7.5
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
result = response.json()
image_base64 = result["data"][0]["b64_json"]
image_bytes = base64.b64decode(image_base64)
# Save the image to a file
with open("Kolors-output.png", "wb") as f:
f.write(image_bytes)
print("Image generated successfully and saved as Kolors-output.png")
else:
print(f"Request failed, status code: {response.status_code}")
print(f"Error message: {response.text}")
For other programming languages, you can refer to the sample codes in the API Documentation.