使用 Google Gemini 原生格式发送请求。Anyone 支持 Gemini SDK 直接调用。
Anyone 在 /v1beta/models/{model} 路径下提供 Google Gemini 兼容端点,与 Google AI SDK 和 Gemini REST API 的格式一致。使用 x-goog-api-key 头或 key 查询参数传入你的 Anyone API key 进行认证——无需 Google 凭据。Anyone 将请求路由到你在 URL 路径中指定的模型对应的上游渠道。
import google.generativeai as genaigenai.configure( api_key="YOUR_TOKEN", client_options={"api_endpoint": "https://api.anyone.ai"},)model = genai.GenerativeModel("gemini-3.1-pro-preview")response = model.generate_content("Explain the difference between RAM and ROM.")print(response.text)
响应示例:
{ "candidates": [ { "content": { "role": "model", "parts": [ { "text": "RAM (Random Access Memory) is volatile memory used for temporary storage while your computer is running..." } ] }, "finishReason": "STOP", "index": 0, "safetyRatings": [] } ], "usageMetadata": { "promptTokenCount": 11, "candidatesTokenCount": 142, "totalTokenCount": 153 }}
curl "https://api.anyone.ai/v1beta/models/gemini-3.1-pro-preview:generateContent" \ -H "x-goog-api-key: YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "systemInstruction": { "parts": [{"text": "You are a geography expert."}] }, "contents": [ {"role": "user", "parts": [{"text": "What is the longest river in Africa?"}]}, {"role": "model", "parts": [{"text": "The Nile is the longest river in Africa."}]}, {"role": "user", "parts": [{"text": "How long is it in kilometers?"}]} ] }'