Generate Image
Interface description: Generate images synchronously, and return the generation results based on the selected model and prompt words.
Before calling this interface, please request the “Image Generation Model” interface (GET /api/ai/models/image/generation) to obtain the currently available model list and the size, quality, style and price supported by each model, and then fill in the parameters of this interface accordingly.
The image is generated as Wen Sheng Picture: Generate a new image only through text prompts, without passing in pictures. If you need to modify or redraw based on existing images, please use the “Edit Image” interface.
If you are already using the OpenAI SDK or ecological tools, you can use the OpenAI compatible endpoint “OpenAI Image Generation” instead.
curl --request POST \
--url https://aitoearn.cn/api/ai/image/generate \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--data '
{
"prompt": "A cute orange cat sitting by a window, soft natural light",
"model": "gpt-image-2"
}
'import requests
url = "https://aitoearn.cn/api/ai/image/generate"
payload = {
"prompt": "A cute orange cat sitting by a window, soft natural light",
"model": "gpt-image-2"
}
headers = {
"X-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'A cute orange cat sitting by a window, soft natural light',
model: 'gpt-image-2'
})
};
fetch('https://aitoearn.cn/api/ai/image/generate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://aitoearn.cn/api/ai/image/generate"
payload := strings.NewReader("{\n \"prompt\": \"A cute orange cat sitting by a window, soft natural light\",\n \"model\": \"gpt-image-2\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"code": 0,
"message": "Request succeeded",
"data": {
"created": 1,
"list": [
{
"url": "string",
"b64_json": "string",
"revised_prompt": "string"
}
],
"usage": {
"input_tokens": 1,
"output_tokens": 1,
"total_tokens": 1
},
"background": "string",
"output_format": "string",
"quality": "string",
"size": "string"
}
}Authorizations
Need to get API Key from AiToEarn. Click to go to "API Key Obtaining Tutorial".
Body
Image description tips
1 - 4000"A cute orange cat sitting by a window, soft natural light"
Image generation model name. First call the "Image Generation Model" interface (GET /api/ai/models/image/generation) and pass in the data[n].name returned by it; the size, quality, style and price supported by each model shall be subject to the return of this interface.
"gpt-image-2"
Image quality. The optional values vary from model to model, and are subject to the data[n].qualities returned by the "Image Generation Model" interface.
"low"
Return format
url, b64_json "url"
Image size. Available values vary by model; use data[n].sizes from Image Generation Models. Pricing varies by size in data[n].pricing. The example uses 1024x1024, which has the lowest price of 1 credit.
"1024x1024"
Response
The request has been processed by the service. Business success is determined by whether the response body has code === 0.
Business status code. 0 means success; non-zero means a business error.
Response message.
Hide child attributes
Hide child attributes
Create timestamp
background
Output format
Quality level
Image size
Request ID.
Error response timestamp in Unix milliseconds.
curl --request POST \
--url https://aitoearn.cn/api/ai/image/generate \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--data '
{
"prompt": "A cute orange cat sitting by a window, soft natural light",
"model": "gpt-image-2"
}
'import requests
url = "https://aitoearn.cn/api/ai/image/generate"
payload = {
"prompt": "A cute orange cat sitting by a window, soft natural light",
"model": "gpt-image-2"
}
headers = {
"X-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'A cute orange cat sitting by a window, soft natural light',
model: 'gpt-image-2'
})
};
fetch('https://aitoearn.cn/api/ai/image/generate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://aitoearn.cn/api/ai/image/generate"
payload := strings.NewReader("{\n \"prompt\": \"A cute orange cat sitting by a window, soft natural light\",\n \"model\": \"gpt-image-2\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"code": 0,
"message": "Request succeeded",
"data": {
"created": 1,
"list": [
{
"url": "string",
"b64_json": "string",
"revised_prompt": "string"
}
],
"usage": {
"input_tokens": 1,
"output_tokens": 1,
"total_tokens": 1
},
"background": "string",
"output_format": "string",
"quality": "string",
"size": "string"
}
}
