Google AI for Developers — Gemini API
The Gemini API by Google AI is a multimodal generative AI service that supports understanding and generation across text, images, video, audio, and PDF. It provides structured outputs, function calling, context caching, batch processing, embeddings, and token counting, suitable for chat agents, content generation, RAG, agent tool use, and large-scale pipelines.
支持模型
API 接口列表
List available Gemini models (stable and preview), returning model names, supported modalities, context window, and capability flags.
{
"url": "https://generativelanguage.googleapis.com/v1beta/models?key=YOUR_API_KEY"
}Get detailed information for a specific model, such as supported input/output types, token limits, and features.
{
"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash?key=YOUR_API_KEY"
}Generate content (text and multimodal). Supports structured outputs, function calling, context caching, and tool use.
{
"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=YOUR_API_KEY",
"body": {
"contents": [
{
"role": "user",
"parts": [
{
"text": "用 3 点概述 Gemini API 的核心能力。"
}
]
}
]
}
}Generate content with server-streaming responses, suitable for low-latency output scenarios.
{
"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?key=YOUR_API_KEY",
"body": {
"contents": [
{
"role": "user",
"parts": [
{
"text": "请逐步流式输出结果。"
}
]
}
]
}
}Count tokens for prompts and candidates to estimate cost and quota usage.
{
"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:countTokens?key=YOUR_API_KEY",
"body": {
"contents": [
{
"role": "user",
"parts": [
{
"text": "这段文字的 token 数是多少?"
}
]
}
]
}
}Generate an embedding vector for a single content item for RAG and semantic search.
{
"url": "https://generativelanguage.googleapis.com/v1beta/models/embedding-001:embedContent?key=YOUR_API_KEY",
"body": {
"content": {
"parts": [
{
"text": "检索增强的文档片段"
}
]
}
}
}Generate embeddings in batch for multiple items to improve throughput and reduce overall cost.
{
"url": "https://generativelanguage.googleapis.com/v1beta/models/embedding-001:batchEmbedContents?key=YOUR_API_KEY",
"body": {
"requests": [
{
"content": {
"parts": [
{
"text": "文档 A"
}
]
}
},
{
"content": {
"parts": [
{
"text": "文档 B"
}
]
}
}
]
}
}