Use this file to discover all available pages before exploring further.
In addition to the OpenAI-compatible format, APIYI also lets you call the API using Gemini’s official native format. This means you can migrate existing Gemini code seamlessly, or use the native request bodies of Google’s official Gemini SDK to interact with APIYI.
Seamless compatibility: Use Gemini’s official request and response structures directly, with no conversion required.
Full feature coverage: Supports all native Gemini features, including multimodal input (text, image, video), function calling, code execution, and more.
Reasoning capabilities: Full support for chain-of-thought reasoning in the Gemini 2.5 series.
Easy migration: If you already have a Gemini project, you can switch to APIYI quickly and enjoy a more flexible service.
We recommend using Google’s latest official google-genai Python SDK (the unified Gen AI SDK). The legacy google-generative-ai package was deprecated on November 30, 2025.
First, make sure the google-genai library is installed:
from google import genai{/* Configure APIYI service */}client = genai.Client( api_key="YOUR_API_KEY", # Your APIYI key http_options={"base_url": "https://api.apiyi.com"}){/* Generate content with a Gemini model */}response = client.models.generate_content( model='gemini-3-pro-preview', contents='Your prompt here')print(response.text)
from google import genaiclient = genai.Client( api_key="YOUR_API_KEY", http_options={"base_url": "https://api.apiyi.com"}){/* Send the request */}response = client.models.generate_content( model='gemini-2.0-flash', contents="Tell me a science fiction story about artificial intelligence."){/* Print the result */}print(response.text)
If you want to see the model’s thought process (thinking tokens), set include_thoughts=True:
from google import genaiclient = genai.Client( api_key="YOUR_API_KEY", http_options={"base_url": "https://api.apiyi.com"}){/* Enable the thought process display */}response = client.models.generate_content( model='gemini-2.5-flash', contents="Analyze the time complexity of the following code: def fibonacci(n): return n if n <= 1 else fibonacci(n-1) + fibonacci(n-2)", config={ "thinking_budget": 8192, "include_thoughts": True # Show the thought process }){/* Iterate over all parts, including the thought process */}for part in response.candidates[0].content.parts: if hasattr(part, 'thought') and part.thought: print(f"💭 Thought process: {part.text}") else: print(f"📝 Final answer: {part.text}")
Billing note: Thinking tokens produced during reasoning count toward the output token cost. Using a high reasoning budget may increase your bill.
from google import genaifrom PIL import Imageclient = genai.Client( api_key="YOUR_API_KEY", http_options={"base_url": "https://api.apiyi.com"}){/* Load a local image */}img = Image.open('path/to/your/image.jpg'){/* Multimodal request */}response = client.models.generate_content( model='gemini-2.0-flash', contents=[ "Describe this image in detail, including the main elements, colors, and composition.", img ])print(response.text)
from google import genaiclient = genai.Client( api_key="YOUR_API_KEY", http_options={"base_url": "https://api.apiyi.com"}){/* Upload a video file */}video_file = client.files.upload(path='path/to/video.mp4'){/* Analyze the video content */}response = client.models.generate_content( model='gemini-2.5-flash', contents=[ "Summarize the main content and key points of this video.", video_file ])print(response.text)
from google import genaiclient = genai.Client( api_key="YOUR_API_KEY", http_options={"base_url": "https://api.apiyi.com"}){/* Upload an audio file */}audio_file = client.files.upload(path='path/to/audio.mp3'){/* Transcribe and analyze the audio */}response = client.models.generate_content( model='gemini-2.5-flash', contents=[ "Transcribe this audio and summarize the main topics.", audio_file ])print(response.text)
To save on token costs, you can adjust the resolution of media files:
from google import genaifrom PIL import Imageclient = genai.Client( api_key="YOUR_API_KEY", http_options={"base_url": "https://api.apiyi.com"}){/* Process the image at a lower resolution to reduce cost */}img = Image.open('large_image.jpg')response = client.models.generate_content( model='gemini-2.0-flash', contents=[ "What is the subject of this image?", img ], config={ "response_modalities": ["TEXT"], "media_resolution": "MEDIA_RESOLUTION_LOW" # LOW | MEDIUM | HIGH })print(response.text)
Gemini models can execute Python code automatically, which makes them ideal for data analysis scenarios.
from google import genaiclient = genai.Client( api_key="YOUR_API_KEY", http_options={"base_url": "https://api.apiyi.com"}){/* Data analysis example with the code execution tool enabled */}response = client.models.generate_content( model='gemini-2.5-flash', contents="""Suppose I have the following sales data:- Product A: 100 units at $50 each- Product B: 200 units at $30 each- Product C: 150 units at $40 eachPlease calculate:1. Total revenue2. Average unit price3. Draw a bar chart showing revenue distribution""", config={'tools': [{'code_execution': {}}]}){/* Inspect the executed code and its results */}for part in response.candidates[0].content.parts: if hasattr(part, 'executable_code'): print(f"Executed code:\n{part.executable_code.code}") if hasattr(part, 'code_execution_result'): print(f"Execution result:\n{part.code_execution_result.output}") if hasattr(part, 'text'): print(f"Analysis:\n{part.text}")
Code execution limits:
Only Python code is supported.
The execution environment is a sandbox with no network or file system access.
from google import genai{/* Configure the tool-calling mode */}response = client.models.generate_content( model='gemini-2.5-flash', contents="What's the weather in Beijing right now? What's the temperature in Celsius?", config={ 'tools': tools, 'tool_config': {'function_calling_config': {'mode': 'AUTO'}} }){/* Check whether a tool needs to be called */}function_call = response.candidates[0].content.parts[0].function_callif function_call: print(f"Calling tool: {function_call.name}") print(f"Arguments: {dict(function_call.args)}") {/* Call your real weather API here */} def get_current_weather(location, unit="celsius"): # Replace this with a real weather API call return { "location": location, "temperature": 22, "unit": unit, "condition": "sunny" } {/* Get the tool execution result */} weather_data = get_current_weather(**dict(function_call.args)) {/* Return the result to the model */} from google.genai import types response = client.models.generate_content( model='gemini-2.5-flash', contents=[ types.Content( parts=[ types.Part( function_response=types.FunctionResponse( name=function_call.name, response=weather_data ) ) ] ) ] ) print(f"Final answer: {response.text}")
Tool-calling modes:
mode: 'AUTO': The model decides whether to call a tool (recommended).
If you need to call other types of models (such as the OpenAI series) or use the OpenAI-compatible format, see the Using OpenAI Official SDK documentation.