跳转到主要内容
Qhaigc supports the native Gemini API format through the /v1beta/models/{model}:generateContent path. Send requests exactly as you would to the Google AI API — Qhaigc proxies and authenticates them for you using your Qhaigc API key, so you do not need a separate Google API key. Endpoint: POST https://api.qhaigc.net/v1beta/models/{model}:generateContent Replace {model} in the path with the model name, such as gemini-2.5-flash or gemini-2.5-pro.
You can also pass "style": "gemini" in the body of POST /v1/chat/completions to receive a Gemini-format response from the unified endpoint. The native path shown here is recommended when you are migrating existing Gemini SDK code.

Path Parameter

model
string
必填
The Gemini model name. Examples: gemini-2.5-flash, gemini-2.5-pro.

Request Parameters

contents
array
必填
The conversation contents. Each element has a role ("user" or "model") and a parts array.
generationConfig
object
Generation parameters.
safetySettings
array
Safety filter configuration. Pass an array of category/threshold objects to adjust content filtering.
tools
array
Function calling tool definitions. Pass an array of tool objects to enable function calling.

Response Fields

candidates
array
Array of generated response candidates.
usageMetadata
object
Token usage for this request.

Code Examples

import requests

url = "https://api.qhaigc.net/v1beta/models/gemini-2.5-flash:generateContent"
headers = {
    "Authorization": "Bearer sk-your-api-key-here",
    "Content-Type": "application/json"
}

payload = {
    "contents": [
        {
            "role": "user",
            "parts": [{"text": "Explain how RAG works in three concise steps."}]
        }
    ],
    "generationConfig": {
        "temperature": 0.4,
        "maxOutputTokens": 512
    }
}

response = requests.post(url, headers=headers, json=payload)
data = response.json()
print(data["candidates"][0]["content"]["parts"][0]["text"])

Example Response

{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "text": "RAG works in three steps:\n\n1. **Retrieve** — search a knowledge base for documents relevant to the user's query...\n2. **Augment** — prepend those documents to the prompt as context...\n3. **Generate** — the LLM produces a grounded answer using the retrieved context."
          }
        ]
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 18,
    "candidatesTokenCount": 76,
    "totalTokenCount": 94
  }
}

Multi-Turn Conversation

To send a multi-turn conversation, include prior turns in the contents array, alternating "user" and "model" roles:
payload = {
    "contents": [
        {"role": "user", "parts": [{"text": "What is a vector database?"}]},
        {"role": "model", "parts": [{"text": "A vector database stores embeddings..."}]},
        {"role": "user", "parts": [{"text": "Which ones are most popular?"}]}
    ],
    "generationConfig": {"temperature": 0.5, "maxOutputTokens": 256}
}