Skip to content

Latest commit

 

History

History
472 lines (424 loc) · 10.7 KB

api-examples.md

File metadata and controls

472 lines (424 loc) · 10.7 KB

API Usage Examples

This document provides simple API usage examples, including OpenAI-compatible API, Gemini native API, and Anthropic-compatible API formats.

🤖 OpenAI-Compatible 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-flash-lite-latest",
    "messages": [
      {
        "role": "user",
        "content": "Hello, how are you?"
      }
    ],
    "stream": false
  }'

🌊 Streaming Response

curl -X POST http://localhost:7860/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "model": "gemini-flash-lite-latest",
    "messages": [
      {
        "role": "user",
        "content": "Write a short poem about autumn"
      }
    ],
    "stream": true
  }'

🖼️ Generate Image Official Docs

curl -X POST http://localhost:7860/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "model": "gemini-3.1-flash-lite-image",
    "messages": [
      {
        "role": "user",
        "content": "Generate a kitten"
      }
    ],
    "stream": false
  }'

🫗 Stream Generation

curl -X POST http://localhost:7860/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "model": "gemini-3.1-flash-lite-image",
    "messages": [
      {
        "role": "user",
        "content": "Generate a kitten"
      }
    ],
    "stream": true
  }'

📐 Text Embeddings Official Docs

curl -X POST http://localhost:7860/v1/embeddings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "model": "gemini-embedding-001",
    "input": "What is artificial intelligence?"
  }'

💬 Responses API

curl -X POST http://localhost:7860/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "model": "gemini-flash-lite-latest",
    "input": "Summarize the main idea of functional programming in 3 sentences.",
    "stream": false
  }'

🌊 Streaming Responses API

curl -X POST http://localhost:7860/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "model": "gemini-flash-lite-latest",
    "input": [
      {
        "role": "user",
        "content": [
          {
            "type": "input_text",
            "text": "Write a short poem about autumn."
          }
        ]
      }
    ],
    "stream": true
  }'

♊ Gemini Native API Format

curl -X POST http://localhost:7860/v1beta/models/gemini-flash-lite-latest:generateContent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Hello, how are you?"
          }
        ]
      }
    ]
  }'

🌊 Streaming Content Generation

curl -X POST http://localhost:7860/v1beta/models/gemini-flash-lite-latest:streamGenerateContent?alt=sse \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Write a short poem about autumn"
          }
        ]
      }
    ]
  }'

🖼️ Generate Image Official Docs

curl -X POST http://localhost:7860/v1beta/models/gemini-3.1-flash-lite-image:generateContent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Generate a kitten"
          }
        ]
      }
    ]
  }'

🫗 Stream Generation

curl -X POST http://localhost:7860/v1beta/models/gemini-3.1-flash-lite-image:streamGenerateContent?alt=sse \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Generate a kitten"
          }
        ]
      }
    ]
  }'

🎵 Lyria Music Generation Official Docs

Generate a 30-Second Music Clip

curl -X POST http://localhost:7860/v1beta/models/lyria-3-clip-preview:generateContent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "text": "Create a 30-second cheerful acoustic folk song with guitar and harmonica."
          }
        ]
      }
    ]
  }'

Generate a Full-Length Song

curl -X POST http://localhost:7860/v1beta/models/lyria-3.5:generateContent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "text": "Create an epic cinematic orchestral piece about a journey home. Start with a solo piano, build through sweeping strings, and end with a powerful climax."
          }
        ]
      }
    ]
  }'

🎧 Audio Transcription Official Docs

curl -X POST http://localhost:7860/v1beta/models/gemini-3.5-transcribe:generateContent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "fileData": {
              "fileUri": "YOUR_FILE_URI",
              "mimeType": "audio/mp3"
            }
          }
        ]
      }
    ]
  }'

🎤 TTS (Text-to-Speech) Official Docs

Single-Speaker Speech

curl -X POST http://localhost:7860/v1beta/models/gemini-3.8-flash-tts:generateContent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Have a wonderful day!",
            "speech_metadata": {
              "style": "cheerful and friendly"
            }
          }
        ]
      }
    ],
    "generationConfig": {
      "responseModalities": ["AUDIO"],
      "speechConfig": {
        "voiceConfig": {
          "voice": "Kore"
        }
      }
    }
  }'

Multi-Speaker Dialogue

For multi-speaker dialogue, place each speaker's text in a separate part and match speech_metadata.speaker to the voice configuration.

curl -X POST http://localhost:7860/v1beta/models/gemini-3.8-flash-tts:generateContent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "How is it going today, Jane?",
            "speech_metadata": {
              "speaker": "Joe",
              "style": "cheerful and friendly"
            }
          },
          {
            "text": "Not too bad. How about you? Ready to test these new voices?",
            "speech_metadata": {
              "speaker": "Jane",
              "style": "calm and relaxed"
            }
          }
        ]
      }
    ],
    "generationConfig": {
      "responseModalities": ["AUDIO"],
      "speechConfig": {
        "multiSpeakerVoiceConfig": {
          "speakerVoiceConfigs": [
            {
              "speaker": "Joe",
              "voiceConfig": {
                "prebuiltVoiceConfig": {
                  "voiceName": "Puck"
                }
              }
            },
            {
              "speaker": "Jane",
              "voiceConfig": {
                "prebuiltVoiceConfig": {
                  "voiceName": "Kore"
                }
              }
            }
          ]
        }
      }
    }
  }'

📐 Text Embeddings Official Docs

Use the embedContent or batchEmbedContents endpoint to generate text embedding vectors.

Single Text Embedding

curl -X POST http://localhost:7860/v1beta/models/gemini-embedding-001:embedContent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-1" \
  -d '{
    "model": "models/gemini-embedding-001",
    "content": {
      "parts": [
        {
          "text": "What is artificial intelligence?"
        }
      ]
    }
  }'

Single Batch Text Embedding

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": "What is artificial intelligence?"
            }
          ]
        }
      }
    ]
  }'

Batch Text Embeddings

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": "What is artificial intelligence?"
            }
          ]
        }
      },
      {
        "model": "models/gemini-embedding-001",
        "content": {
          "parts": [
            {
              "text": "What is the difference between machine learning and deep learning?"
            }
          ]
        }
      }
    ]
  }'

👤 Anthropic Compatible API

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-flash-lite-latest",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "Hello, how are you?"
      }
    ],
    "stream": false
  }'

🌊 Streaming Response

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-flash-lite-latest",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "Write a poem about autumn"
      }
    ],
    "stream": true
  }'