開始使用

介紹

MiniToolAI API 提供了一個簡單的接口,能夠使用最先進的 AI 模型進行自然語言處理、圖像生成、文字轉語音。請參閱本指南以了解如何生成類似人類的回應(ChatGPT)、根據文本描述生成圖像。

創建 API 金鑰

sk-*************   登入以生成 API 金鑰

儲值

API 請求的費用將從您的餘額中扣除。

儲值

授權

每個 API 請求的標頭中必須包含 API 金鑰。

Header: "Authorization: Bearer API_key"

 

 

 

 

ChatGPT API

根據提供的聊天內容生成模型回應。

Python PHP
import requests
import json
API_Url = "https://minitoolai.com/api/chat-completions/"
API_Key = "MiniToolAI_API_Key"
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {API_Key}"
}
data = {
    "model": "gpt-4o-mini", #gpt-4o, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano
    "messages": [
		{"role": "developer", "content": "You are a helpful assistant."},
		{"role": "user", "content": "Hello"},
		{"role": "assistant", "content": "How can I help you today?"},
		{"role": "user", "content": "What's the largest U.S. state by area?"}
    ],
	"temperature": 1.0,
	"max_completion_tokens": 1000
}

response = requests.post(API_Url, headers=headers, json=data, stream=True)

#single result
print(response.text) 

#streamed
for line in response.iter_lines():
    if line:
        decode_line = line.decode('utf-8')
        print(decode_line)
<?php

$api_url = "https://minitoolai.com/api/chat-completions/";
$api_key = "MiniToolAI_API_Key"; 

$data = [
    "model" => "gpt-4o-mini", //gpt-4o, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano
    "messages" => [
        ["role" => "developer", "content" => "You are a helpful assistant."],
        ["role" => "user", "content" => "Hello"],
        ["role" => "assistant", "content" => "How can I help you today?"],
        ["role" => "user", "content" => "What's the largest U.S. state by area?"],
    ],
    "temperature" => 1.0,
    "max_completion_tokens" => 1000
];

$headers = [
    "Content-Type: application/json",
    "Authorization: Bearer $api_key"
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); 
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

// streamed
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($ch, $data) {
    echo $data;
    ob_flush(); 
    flush();     
    return strlen($data); 
});

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo "cURL error: " . curl_error($ch);
} 

curl_close($ch);

?>
#data with image input
data = {
    "model": "gpt-4o-mini", #gpt-4o
    "messages": [
        {"role": "developer", "content": "You are a helpful assistant."},
        {
            "role": "user", 
            "content": [
                {"type": "text", "text": "What's in this image?"},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://example.com/image.jpg", #jpg, jpeg, png, webp or gif
                        "detail": "auto" #auto, high or low
                    }
                }
            ]
        }

    ],
    "temperature": 0.7,
    "max_completion_tokens": 300
}
//data with image input
$data = [
    "model" => "gpt-4o-mini", // gpt-4o
    "messages" => [
        ["role" => "developer", "content" => "You are a helpful assistant."],
        [
            "role" => "user",
            "content" => [
                [
                    "type" => "text",
                    "text" => "What's in this image?"
                ],
                [
                    "type" => "image_url",
                    "image_url" => [
                        "url" => "https://example.com/image.jpg", // jpg, jpeg, png, webp or gif
                        "detail" => "auto" // auto, high or low
                    ]
                ]
            ]
        ]
    ],
    "temperature" => 0.7,
    "max_completion_tokens" => 300
];

請求主體

messages 陣列 必填

包含當前對話的消息列表。

  • Developer message: 開發人員提供的指令,無論使用者發送的消息如何,模型都應遵循這些指令。
  • User message: 使用者發送的消息,包含提示或額外的上下文資訊。
  • Assistant message: 模型根據使用者消息回應的內容。

model 字串 必填

要使用的模型 ID

可用模型: gpt-4o, gpt-4o-mini, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano

temperature 數字或 null 選填

預設為 1

設定取樣溫度,範圍為 0.0 到 2.0。較高的值(如 0.8)會使輸出更具創意,而較低的值(如 0.2)則會使輸出更精確且具決定性。

max_completion_tokens 整數或 null 選填

預設為 1000

可生成的最大 Token 數量。

回應

data: {"id":"chatcmpl-B5qoZsT8kFDNJK3UyGLiJmjv6Pp90","object":"chat.completion.chunk","created":1740734359,"model":"gpt-4o-mini-2024-07-18","service_tier":"default","system_fingerprint":"fp_06737a9306","choices":[{"index":0,"delta":{"content":"Ok"},"logprobs":null,"finish_reason":null}],"usage":null}

data: {"id":"chatcmpl-B5qoZsT8kFDNJK3UyGLiJmjv6Pp90","object":"chat.completion.chunk","created":1740734359,"model":"gpt-4o-mini-2024-07-18","service_tier":"default","system_fingerprint":"fp_06737a9306","choices":[{"index":0,"delta":{"content":"."},"logprobs":null,"finish_reason":null}],"usage":null}

data: {"id":"chatcmpl-B5qoZsT8kFDNJK3UyGLiJmjv6Pp90","object":"chat.completion.chunk","created":1740734359,"model":"gpt-4o-mini-2024-07-18","service_tier":"default","system_fingerprint":"fp_06737a9306","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}],"usage":null}

data: {"id":"chatcmpl-B5qoZsT8kFDNJK3UyGLiJmjv6Pp90","object":"chat.completion.chunk","created":1740734359,"model":"gpt-4o-mini-2024-07-18","service_tier":"default","system_fingerprint":"fp_06737a9306","choices":[],"usage":{"prompt_tokens":17,"completion_tokens":3,"total_tokens":20,"prompt_tokens_details":{"cached_tokens":0,"audio_tokens":0},"completion_tokens_details":{"reasoning_tokens":0,"audio_tokens":0,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0}}}

data: [DONE]

 

 

 

 

文字轉圖像

根據提示生成圖像。

Python PHP
import requests
import json
url = "https://minitoolai.com/api/texttoimage/"
API_Key = "MiniToolAI_API_Key"
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {API_Key}"
}
data = {
    "model": "realvision",
    "prompt": "Ultra realistic portrait of a 20 year old woman, wearing an elegant black gown, joyful expression, deep shadows, cinematic composition, moody lighting",
    "negativePrompt": "unrealistic eyes, malformed features, ugly drawn",
    "scheduler": "DPM++ SDE",
    "steps": 4,
    "cfgScale": 2.0,
    "width": 1152,
    "height": 768
}
response = requests.post(url, json=data, headers=headers)
print(response.text)

'''
#response
Success:
{"status":"success","jobid":12345678,"signature":"abcxyz123"}
Error:
{"status":"error","jobid":null,"signature":null}
'''
<?php
// API URL and Key
$url = "https://minitoolai.com/api/texttoimage/";
$API_Key = "MiniToolAI_API_Key";

// Headers
$headers = [
    "Content-Type: application/json",
    "Authorization: Bearer $API_Key"
];

// Data to be sent in the request
$data = [
    "model" => "realvision",
    "prompt" => "Ultra realistic portrait of a 20 year old woman, wearing an elegant black gown, joyful expression, deep shadows, cinematic composition, moody lighting",
    "negativePrompt" => "unrealistic eyes, malformed features, ugly drawn",
    "scheduler" => "DPM++ SDE",
    "steps" => 4,
    "cfgScale" => 2.0,
    "width" => 1152,
    "height" => 768
];

// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

// Execute the cURL request
$response = curl_exec($ch);

echo $response;

// Close the cURL session
curl_close($ch);

/*
Response:
Success:
{"status":"success","jobid":12345678,"signature":"abcxyz123"}
Error:
{"status":"error","jobid":null,"signature":null}
*/
?>

擷取任務狀態與結果

curl -X POST https://minitoolai.com/api/texttoimage/jobs/ \
  -H "Content-Type: application/json" \
  -d '{
    "jobid": "12345678",
    "signature": "abcxyz123"
  }'

回應

{
  "status": "success",
  "image_url": "https://...",
  "message": "success"
}

model 字串 必填

要使用的模型 ID

可用模型: "realvision", "juggernaut", "autismmix", "dreamshaper", "valhalla", "mixrealistic", "campursari", "reality", "extrarealistic", "realism", "realgirls", "realityreborn", "amigo", "simplemix", "beautifulrealistic"

prompt 字串 必填

圖像描述

negativePrompt 字串或 null 選填

描述您希望從生成圖像中排除的內容。

scheduler 字串或 null 選填

控制圖像生成過程中如何去除雜訊。

預設為 "DPM++ SDE"

可能的值為: "Euler a", "Euler", "LMS", "Heun", "DPM2", "DPM2 a", "DPM++ 2S a", "DPM++ 2M", "DPM++ SDE", "DPM++ 2M SDE", "DPM fast", "LMS Karras", "DPM2 Karras", "DPM2 a Karras", "DPM++ 2S a Karras", "DPM++ 2M Karras", "DPM++ SDE Karras", "DPM++ 2M SDE Karras"

steps 整數或 null 選填

圖像生成過程中的步驟數,介於 1 到 8 之間。

預設為 4

cfgScale 數字或 null 選填

cfgScale 控制模型應遵循給定文字提示的程度。在創造力與提示準確性之間取得平衡,範圍為 1 到 7。

預設為 2

cfgScale < 4 → 更具創意的圖像, cfgScale > 4 → 更接近提示,創意較低

width/height 整數或 null 選填

生成圖像的大小,範圍為 256 到 1344。

預設為 1024

 

 

 

 

API 定價

GPT 模型

每百萬個 Token 的價格

模型 輸入 輸出
gpt-4o-mini $0.15 $0.60
gpt-4o $2.50 $10.00
gpt-4.1 $2.00 $8.00
gpt-4.1-mini $0.40 $1.60
gpt-4.1-nano $0.10 $0.40

圖像生成

模型 每張圖片的價格
所有模型 $0.0015

 

 

 

 

API 使用量

登入以查看 API 使用情況

文字生成

圖像生成