Skip to content

Gemini Native Format

Call Gemini models via the Google Gemini native API protocol. Fully compatible with Gemini's native request format, path structure, and response format.

Quick Start

Step 1: Get your API Key from the Console.

Step 2: Send a request:

bash
curl -X POST "https://open.dieyuyun.com/v1beta/models/gemini-2.5-pro:generateContent" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxx" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "Hello, introduce yourself"}]
      }
    ]
  }'
python
import requests

url = "https://open.dieyuyun.com/v1beta/models/gemini-2.5-pro:generateContent"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk-xxx"
}
payload = {
    "contents": [
        {
            "role": "user",
            "parts": [{"text": "Hello, introduce yourself"}]
        }
    ]
}

response = requests.post(url, json=payload, headers=headers)
result = response.json()
print(result["candidates"][0]["content"]["parts"][0]["text"])
javascript
const response = await fetch('https://open.dieyuyun.com/v1beta/models/gemini-2.5-pro:generateContent', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer sk-xxx',
  },
  body: JSON.stringify({
    contents: [
      {
        role: 'user',
        parts: [{ text: 'Hello, introduce yourself' }],
      },
    ],
  }),
})

const result = await response.json()
console.log(result.candidates[0].content.parts[0].text)

Step 3: Read the response from candidates[0].content.parts[0].text.

Endpoint

ItemValue
MethodPOST
Path/v1beta/models/{model}:generateContent
/v1beta/models/{model}:streamGenerateContent (streaming)
Base URLhttps://open.dieyuyun.com
ProtocolGoogle Gemini API

Path Parameters

ParameterTypeRequiredDescription
modelstringYesModel identifier, e.g. gemini-2.5-pro
actionstringYesOperation type: generateContent or streamGenerateContent

Authentication

Uses Bearer Token authentication (shares the same API Key as the OpenAI-compatible endpoint):

http
Authorization: Bearer sk-xxx

TIP

The platform uses a unified API Key for all endpoints. No separate Google API Key is needed. Your API Key is securely forwarded to the upstream provider on the server side.

Supported Models

ModelContext LengthDescription
gemini-2.5-pro1MGemini flagship reasoning model
gemini-2.5-flash1MGemini fast model
gemini-2.0-flash1MGemini 2.0 fast model

TIP

See the full model list in the Console.

Request Parameters

FieldTypeRequiredDefaultDescription
contentsarrayYesConversation content list, each with role and parts
systemInstructionobjectNoSystem instruction to define model behavior
generationConfigobjectNoGeneration parameter configuration
safetySettingsarrayNoSafety settings
toolsarrayNoTool definitions
toolConfigobjectNoTool calling configuration

generationConfig Parameters

ParameterTypeDefaultDescription
temperaturenumber1.0Sampling randomness, range 0~2
topPnumber0.95Nucleus sampling parameter
topKinteger40Top-K sampling
maxOutputTokensintegerMaximum output tokens
stopSequencesarrayStrings that stop generation
responseMimeTypestringResponse MIME type, e.g. application/json

contents Structure

json
{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Describe this image" },
        {
          "inline_data": {
            "mime_type": "image/jpeg",
            "data": "/9j/4AAQ..."
          }
        }
      ]
    }
  ]
}

Request Examples

With System Instruction and Generation Config

bash
curl -X POST "https://open.dieyuyun.com/v1beta/models/gemini-2.5-pro:generateContent" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxx" \
  -d '{
    "systemInstruction": {
      "parts": [{"text": "You are a professional translator. Translate to English."}]
    },
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "Artificial intelligence is changing our way of life."}]
      }
    ],
    "generationConfig": {
      "temperature": 0.7,
      "maxOutputTokens": 1024
    }
  }'
python
import requests

url = "https://open.dieyuyun.com/v1beta/models/gemini-2.5-pro:generateContent"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk-xxx"
}
payload = {
    "systemInstruction": {
        "parts": [{"text": "You are a professional translator. Translate to English."}]
    },
    "contents": [
        {
            "role": "user",
            "parts": [{"text": "Artificial intelligence is changing our way of life."}]
        }
    ],
    "generationConfig": {
        "temperature": 0.7,
        "maxOutputTokens": 1024
    }
}

response = requests.post(url, json=payload, headers=headers)
result = response.json()
print(result["candidates"][0]["content"]["parts"][0]["text"])
javascript
const response = await fetch('https://open.dieyuyun.com/v1beta/models/gemini-2.5-pro:generateContent', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer sk-xxx',
  },
  body: JSON.stringify({
    systemInstruction: {
      parts: [{ text: 'You are a professional translator. Translate to English.' }],
    },
    contents: [
      {
        role: 'user',
        parts: [{ text: 'Artificial intelligence is changing our way of life.' }],
      },
    ],
    generationConfig: {
      temperature: 0.7,
      maxOutputTokens: 1024,
    },
  }),
})

const result = await response.json()
console.log(result.candidates[0].content.parts[0].text)

Streaming Output

Use the streamGenerateContent endpoint for streaming responses:

bash
curl -X POST "https://open.dieyuyun.com/v1beta/models/gemini-2.5-pro:streamGenerateContent" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxx" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "Write a poem about the ocean"}]
      }
    ]
  }'

Multimodal Input (Images)

json
{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "What's in this image?" },
        {
          "inline_data": {
            "mime_type": "image/png",
            "data": "iVBORw0KGgo..."
          }
        }
      ]
    }
  ]
}

Function Calling

json
{
  "contents": [
    {
      "role": "user",
      "parts": [{ "text": "What's the weather like in Beijing today?" }]
    }
  ],
  "tools": [
    {
      "functionDeclarations": [
        {
          "name": "get_weather",
          "description": "Get weather information for a city",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {
                "type": "string",
                "description": "City name"
              }
            },
            "required": ["city"]
          }
        }
      ]
    }
  ]
}

Response Format

Successful Response

json
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "Hello! I'm Gemini, a multimodal AI model developed by Google DeepMind. I can process text, images, code, and more."
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 6,
    "candidatesTokenCount": 42,
    "totalTokenCount": 48
  },
  "modelVersion": "gemini-2.5-pro"
}

Field Reference

FieldDescription
candidates[].content.parts[].textResponse text content
candidates[].content.roleRole, model for model responses
candidates[].finishReasonStop reason: STOP, MAX_TOKENS, SAFETY
candidates[].safetyRatingsSafety ratings
usageMetadata.promptTokenCountNumber of input tokens
usageMetadata.candidatesTokenCountNumber of output tokens
usageMetadata.totalTokenCountTotal token count
modelVersionActual model version used

Error Response

json
{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT"
  }
}

See Error Codes for details.

Compatibility

FeatureWuliang AIGoogle Gemini Native API
Path format/v1beta/models/{model}:actionSame
Request body formatGemini native JSONNative protocol
generateContentSupportedNative support
streamGenerateContentSupportedNative support
Multimodal inputSupports base64Supports base64 / file_data
Function callingSupportedNative support
System instructionSupports systemInstructionNative support
AuthenticationBearer Token (platform API Key)Google API Key
safetySettingsPass-through supportNative support

TIP

The platform uses Gemini's native paths and request body format. Successful responses return the Gemini native format directly. The only difference is authentication -- the platform's unified API Key replaces the Google API Key.

Best Practices

  • Choose the right endpoint: Use generateContent for non-streaming and streamGenerateContent for streaming. The path structure is identical.
  • Leverage long context: Gemini supports up to 1M tokens of context, ideal for processing long documents, large codebases, and more.
  • Use systemInstruction: Define model behavior via system instructions. Note the Gemini format: {"parts": [{"text": "..."}]}.
  • Multimodal input: Supports base64-encoded images for image analysis, OCR, and other visual tasks.
  • JSON mode output: Force JSON output via generationConfig.responseMimeType = "application/json".

Rate Limits

See Rate Limits for details.