本文档提供了简要的 API 使用示例,包括 OpenAI 兼容 API、Gemini 原生 API 和 Anthropic 兼容 API 格式。
curl -X POST http://localhost:7860/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"model": "gemini-2.5-flash-lite",
"messages": [
{
"role": "user",
"content": "你好,最近怎么样?"
}
],
"stream": false
}'curl -X POST http://localhost:7860/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"model": "gemini-2.5-flash-lite",
"messages": [
{
"role": "user",
"content": "写一首关于秋天的诗"
}
],
"stream": true
}'🖼️ 生成图片 官方文档
curl -X POST http://localhost:7860/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"model": "gemini-2.5-flash-image",
"messages": [
{
"role": "user",
"content": "生成一只小猫"
}
],
"stream": false
}'curl -X POST http://localhost:7860/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"model": "gemini-2.5-flash-image",
"messages": [
{
"role": "user",
"content": "生成一只小猫"
}
],
"stream": true
}'curl -X POST http://localhost:7860/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"model": "gemini-2.5-flash-lite",
"input": "请用三句话总结函数式编程的核心思想。",
"stream": false
}'curl -X POST http://localhost:7860/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"model": "gemini-2.5-flash-lite",
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "写一首关于秋天的短诗。"
}
]
}
],
"stream": true
}'curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-lite:generateContent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,最近怎么样?"
}
]
}
]
}'curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-lite:streamGenerateContent?alt=sse \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "写一首关于秋天的诗"
}
]
}
]
}'🖼️ 生成图片 官方文档
curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-image:generateContent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "生成一只小猫"
}
]
}
]
}'curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-image:streamGenerateContent?alt=sse \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "生成一只小猫"
}
]
}
]
}'🎨 Imagen 图像生成 官方文档
使用 imagen 系列模型通过 :predict 端点生成图像。
curl -X POST http://localhost:7860/v1beta/models/imagen-4.0-generate-001:predict \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"instances": [
{
"prompt": "机器人手持红色滑板"
}
],
"parameters": {
"sampleCount": 1
}
}'调整 sampleCount 可一次生成多张图像(最多 4 张)。
curl -X POST http://localhost:7860/v1beta/models/imagen-4.0-generate-001:predict \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"instances": [
{
"prompt": "夕阳下的未来城市,天空中有飞行汽车"
}
],
"parameters": {
"sampleCount": 4
}
}'💡 提示:Imagen 响应返回的是 base64 编码的图像数据,每张生成的图像都会包含在
predictions数组中。
🎤 TTS 语音合成 官方文档
curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-preview-tts:generateContent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,这是一个语音合成测试。"
}
]
}
],
"generationConfig": {
"responseModalities": ["AUDIO"]
}
}'可选声音:Kore、Puck、Charon、Fenrir、Aoede
curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-preview-tts:generateContent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,这是一个语音合成测试。"
}
]
}
],
"generationConfig": {
"responseModalities": ["AUDIO"],
"speechConfig": {
"voiceConfig": {
"prebuiltVoiceConfig": {
"voiceName": "Kore"
}
}
}
}
}'对话内容写在 prompt 中,使用 multiSpeakerVoiceConfig 配置多个说话者的声音(最多 2 个)。
curl -X POST http://localhost:7860/v1beta/models/gemini-2.5-flash-preview-tts:generateContent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "TTS the following conversation between Joe and Jane:\nJoe: How are you today Jane?\nJane: I am doing great, thanks for asking!"
}
]
}
],
"generationConfig": {
"responseModalities": ["AUDIO"],
"speechConfig": {
"multiSpeakerVoiceConfig": {
"speakerVoiceConfigs": [
{
"speaker": "Joe",
"voiceConfig": {
"prebuiltVoiceConfig": {
"voiceName": "Charon"
}
}
},
{
"speaker": "Jane",
"voiceConfig": {
"prebuiltVoiceConfig": {
"voiceName": "Kore"
}
}
}
]
}
}
}
}'💡 提示:TTS 响应返回的是
audio/L16;codec=pcm;rate=24000格式的 base64 编码音频数据,需要解码后转换为 WAV 格式播放。
使用 batchEmbedContents 端点生成文本嵌入向量。
⚠️ 注意:embedContent端点已不再支持,请使用batchEmbedContents端点。
curl -X POST http://localhost:7860/v1beta/models/gemini-embedding-001:batchEmbedContents \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"requests": [
{
"model": "models/gemini-embedding-001",
"content": {
"parts": [
{
"text": "什么是人工智能?"
}
]
}
}
]
}'curl -X POST http://localhost:7860/v1beta/models/gemini-embedding-001:batchEmbedContents \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-1" \
-d '{
"requests": [
{
"model": "models/gemini-embedding-001",
"content": {
"parts": [
{
"text": "什么是人工智能?"
}
]
}
},
{
"model": "models/gemini-embedding-001",
"content": {
"parts": [
{
"text": "机器学习和深度学习有什么区别?"
}
]
}
}
]
}'curl -X POST http://localhost:7860/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key-1" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "gemini-2.5-flash-lite",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "你好,最近怎么样?"
}
],
"stream": false
}'curl -X POST http://localhost:7860/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key-1" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "gemini-2.5-flash-lite",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "写一首关于秋天的诗"
}
],
"stream": true
}'