import requests import json # API配置 url = 'https://api.lingyaai.cn/v1/images/generations' api_key = 'sk-bSjxX2X1FAptXPcBjItcMcbRvcGFZTtRRcUf52BGQr1dscZM' # 请替换为你的实际API密钥 # 请求头 headers = { 'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json' } # 请求数据 data = { 'prompt': '帮我生成一张数字化校园的结构图', 'model': 'nano-banana-pro', 'aspect_ratio': '1:1' } # 发送POST请求 response = requests.post(url, headers=headers, json=data) # 打印响应 print(f'状态码: {response.status_code}') print(f'响应内容: {response.text}') # 如果需要解析JSON响应 if response.status_code == 200: result = response.json() print(f'JSON响应: {json.dumps(result, indent=2, ensure_ascii=False)}')