通过 Media.io OpenAPI 调用 Google Imagen 4,根据文本提示生成高质量、照片级真实感的 AI 图像,支持高级文字渲染。
This skill provides access to Google Imagen 4 through the Media.io OpenAPI. Imagen 4 sets a new standard for photorealism and text rendering accuracy, handling the most complex prompts with ease.
Use this skill when you hear:
VariableRequiredDescriptionAPI_KEYYesMedia.io OpenAPI key, sent as X-API-KEY header. Apply at https://developer.media.io/.
Imagen 4t2i-imagen-4POST https://openapi.media.io/generation/imagen/t2i-imagen-4ParameterTypeRequiredDescriptionpromptstringYesText description for image generationratiostringNoImage aspect ratio (e.g., "1:1", "16:9", "9:16")countsstringNoNumber of images to generate (default: "1")
json
{
"code": 0,
"msg": "",
"data": {
"task_id": "..."
},
"trace_id": "..."
}
bash
pip install requests
python
import os
from scripts.skill_router import Skill
skill = Skill('scripts/c_api_doc_detail.json')
api_key = os.getenv('API_KEY', '')
if not api_key:
raise RuntimeError('API_KEY is not set')
Windows PowerShell:
powershell
$env:API_KEY="your-api-key"
macOS / Linux (bash/zsh):
bash
export API_KEY="your-api-key"
python
import os
from scripts.skill_router import Skill
skill = Skill('scripts/c_api_doc_detail.json')
api_key = os.getenv('API_KEY', '')
if not api_key:
raise RuntimeError('API_KEY is not set')
result = skill.invoke(
'Imagen 4',
{
'prompt': 'a cute puppy, photorealistic, soft natural light, high detail',
'ratio': '1:1',
'counts': '1'
},
api_key=api_key
)
print(result) # Returns task_id when code=0
python
import os
import time
from scripts.skill_router import Skill
skill = Skill('scripts/c_api_doc_detail.json')
api_key = os.getenv('API_KEY', '')
if not api_key:
raise RuntimeError('API_KEY is not set')
task_id = 'your-task-id'
for _ in range(24):
r = skill.invoke('Task Result', {'task_id': task_id}, api_key=api_key)
print(r)
status = (r.get('data') or {}).get('status')
if status in ('completed', 'failed', 'succeeded'):
break
time.sleep(5)
waiting: queuedprocessing: runningcompleted: completed successfullyfailed: failedtimeout: timed outError CodeDescription374004Not authenticated. Apply for an APP KEY at https://developer.media.io/490505Insufficient credits. Recharge before invoking generation APIs