Home›Developer Center›Google Gemini API

Google Gemini API

API DocumentationOpenAI ChatGPT APIAnthropic (Claude) APIGoogle Gemini APIGoogle Search APIGoogle News APIOpenRouter APIAPI Pricing
CLI & Agent Guidescc-switch macOScc-switch Windowscc-switch LinuxOpenCode macOSOpenCode WindowsOpenCode LinuxOpenClaw macOSOpenClaw WindowsOpenClaw LinuxHermes Agent macOSHermes Agent WindowsHermes Agent LinuxClaude Code CLI macOSClaude Code CLI WindowsClaude Code CLI LinuxCodex CLI macOSCodex CLI WindowsCodex CLI Linux
MYAI168 API & MCPMYAI168 MCP CLIMYAI168 MCP Web & App
No matching questions on this page.Search the whole site
Google

Google AI Studio API Relay

Compatible with Google Generative Language API spec (Gemini / Veo / Lyria). Authenticate with an x-goog-api-key: YOUR_API_KEY or Authorization: Bearer YOUR_API_KEY header (never place keys in URL query strings; ?key= query authentication is disabled — the official Google SDK uses the header by default).

POST https://www.myai168.com/en/api/google/v1beta/models/{model}:generateContent

Gemini chat (non-streaming).

curl "https://www.myai168.com/en/api/google/v1beta/models/gemini-3.1-pro-preview:generateContent" \
  -H "x-goog-api-key: YOUR_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents":[{"parts":[{"text":"Hello"}]}]}'
import requests

r = requests.post(
    "https://www.myai168.com/en/api/google/v1beta/models/gemini-3.1-pro-preview:generateContent",
    headers={"x-goog-api-key": "YOUR_DEV_KEY"},
    json={"contents": [{"parts": [{"text": "Hello"}]}]},
)
print(r.json())

POST https://www.myai168.com/en/api/google/v1beta/models/{model}:streamGenerateContent

Gemini chat (SSE streaming). This relay always returns SSE (the server enforces alt=sse toward the upstream), so unlike calling the official Google API directly you do not need to add ?alt=sse to the URL (it is ignored if present).

curl "https://www.myai168.com/en/api/google/v1beta/models/gemini-3.1-pro-preview:streamGenerateContent" \
  -H "x-goog-api-key: YOUR_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents":[{"parts":[{"text":"Hello"}]}]}'
import requests

r = requests.post(
    "https://www.myai168.com/en/api/google/v1beta/models/gemini-3.1-pro-preview:streamGenerateContent",
    headers={"x-goog-api-key": "YOUR_DEV_KEY"},
    json={"contents": [{"parts": [{"text": "Hello"}]}]},
    stream=True,
)
for line in r.iter_lines():
    if line:
        print(line.decode("utf-8"))

POST https://www.myai168.com/en/api/google/v1beta/models/gemini-3-pro-image-preview:generateContent

Nano Banana Pro text-to-image (Gemini multimodal, returns inline_data base64 image).

curl "https://www.myai168.com/en/api/google/v1beta/models/gemini-3-pro-image-preview:generateContent" \
  -H "x-goog-api-key: YOUR_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents":[{"parts":[{"text":"A cat"}]}],"generationConfig":{"responseModalities":["TEXT","IMAGE"]}}'
import requests

r = requests.post(
    "https://www.myai168.com/en/api/google/v1beta/models/gemini-3-pro-image-preview:generateContent",
    headers={"x-goog-api-key": "YOUR_DEV_KEY"},
    json={"contents": [{"parts": [{"text": "A cat"}]}], "generationConfig": {"responseModalities": ["TEXT", "IMAGE"]}},
)
print(r.json())

POST https://www.myai168.com/en/api/google/v1beta/models/veo-{ver}:predictLongRunning

Veo video generation (LRO; first call returns operation name, poll for result).

curl "https://www.myai168.com/en/api/google/v1beta/models/veo-3.1-generate-preview:predictLongRunning" \
  -H "x-goog-api-key: YOUR_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{"instances":[{"prompt":"A cat dancing"}],"parameters":{"durationSeconds":8}}'
import requests

r = requests.post(
    "https://www.myai168.com/en/api/google/v1beta/models/veo-3.1-generate-preview:predictLongRunning",
    headers={"x-goog-api-key": "YOUR_DEV_KEY"},
    json={"instances": [{"prompt": "A cat dancing"}], "parameters": {"durationSeconds": 8}},
)
print(r.json())

POST https://www.myai168.com/en/api/google/v1beta/models/lyria-{ver}:predict

Lyria music generation (returns base64 audio). Note: Google has moved Gemini API music generation to Lyria 3 (lyria-3-clip-preview / lyria-3-pro-preview via the new Interactions API), and the official docs no longer list the lyria-002 :predict interface — this relay keeps forwarding the legacy interface; if the upstream has dropped it you will get an upstream error (no credits deducted). Check Google's official announcements for availability.

curl "https://www.myai168.com/en/api/google/v1beta/models/lyria-002:predict" \
  -H "x-goog-api-key: YOUR_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{"instances":[{"prompt":"Upbeat jazz"}],"parameters":{"sampleCount":1}}'
import requests

r = requests.post(
    "https://www.myai168.com/en/api/google/v1beta/models/lyria-002:predict",
    headers={"x-goog-api-key": "YOUR_DEV_KEY"},
    json={"instances": [{"prompt": "Upbeat jazz"}], "parameters": {"sampleCount": 1}},
)
print(r.json())

GET https://www.myai168.com/en/api/google/v1beta/operations/{name}

Query LRO operation status (used for Veo poll, query endpoint, no credits deducted).

curl "https://www.myai168.com/en/api/google/v1beta/operations/OP_NAME" \
  -H "x-goog-api-key: YOUR_DEV_KEY"
import requests

r = requests.get(
    "https://www.myai168.com/en/api/google/v1beta/operations/OP_NAME",
    headers={"x-goog-api-key": "YOUR_DEV_KEY"},
)
print(r.json())
Request parameters, response format and error codes

Request parameters (generateContent / streamGenerateContent)

The request body is JSON, identical to the official Google spec. Authenticate with an x-goog-api-key or Authorization: Bearer header.

ParameterTypeRequiredDescription
contentsarrayrequiredConversation contents, each {"role": "user" | "model", "parts": [{"text": "..."}]}; parts may also contain inline_data (base64 image / audio).
generationConfigobjectoptionalTemperature, output limits, responseModalities (image models need ["TEXT","IMAGE"]) and other official settings.
systemInstructionobjectoptionalSystem prompt (official spec).
toolsarrayoptionalOfficial tool settings forwarded as-is (Google Search grounding is billed per use).

The model id goes in the URL path (models/{model}:generateContent); models not in the pricing table return "No pricing info! Please use other models!". Veo uses instances + parameters (durationSeconds / numberOfVideos / resolution) and Lyria uses instances + parameters.sampleCount (see the examples above).

Response format

Non-streaming: official JSON — text in candidates[0].content.parts[], usage in usageMetadata; response headers include X-Cost-Points (points charged) and X-Credits-Remaining (balance after the call). Streaming (:streamGenerateContent) is SSE; after the stream ends, SSE comment lines : cost=N / : credits-remaining=M carry the points charged and remaining balance. You can also query GET https://www.myai168.com/en/api/user/get_credits any time.

Error codes

HTTP statusMeaning
401Missing or invalid API key (repeated failures from the same IP are temporarily blocked).
402Insufficient credits (please top up).
400Invalid request body, or model not in the supported list ("No pricing info! Please use other models!").
502Upstream vendor error — never charged.

No points are ever charged on errors (including when the vendor returns no usage info); polling LRO status (operations) is free.

‹ Previous page: Anthropic (Claude) APINext page: Google Search API ›
↑
Question link copied.

Other FAQ pages

API Documentation

  • OpenAI ChatGPT API
  • Anthropic (Claude) API
  • Google Search API
  • Google News API
  • OpenRouter API
  • API Pricing

CLI & Agent Guides

  • cc-switch macOS
  • cc-switch Windows
  • cc-switch Linux
  • OpenCode macOS
  • OpenCode Windows
  • OpenCode Linux
  • OpenClaw macOS
  • OpenClaw Windows
  • OpenClaw Linux
  • Hermes Agent macOS
  • Hermes Agent Windows
  • Hermes Agent Linux
  • Claude Code CLI macOS
  • Claude Code CLI Windows
  • Claude Code CLI Linux
  • Codex CLI macOS
  • Codex CLI Windows
  • Codex CLI Linux

MYAI168 API & MCP

  • MYAI168 MCP CLI
  • MYAI168 MCP Web & App