Back

Gemini API Essential Guide

Aug 2, 20246 minute read

What type of API does Gemini provide?

Based on the search results provided, Gemini appears to have a REST API. The key points are:

  1. Gemini provides a REST API for developers to interact with their platform.
  2. The base URL for the REST API is api.gemini.com/v1 for production and api.sandbox.gemini.com/v1 for the sandbox environment.
  3. Gemini also offers WebSocket APIs for real-time data and order updates.
  4. Authentication: Gemini uses API keys for access to private APIs.
  5. Payload: Requests use JSON payloads that are base64 encoded and included in the request headers.
  6. Rate limits: Public API endpoints are limited to 120 requests per minute, while private API endpoints are limited to 600 requests per minute.
  7. Best practices:
    • Use WebSocket APIs for real-time market data and order updates instead of polling REST endpoints.
    • Don't exceed 1 request per second for public API endpoints and 5 requests per second for private API endpoints.
    • Use the sandbox environment (api.sandbox.gemini.com) for testing purposes.

Does the Gemini API have webhooks?

Webhooks in the Official Gemini API

The official Gemini API does not appear to have native webhook support. The search results do not mention any webhook functionality specifically for the Gemini API.

Alternative Real-time Data Options

While webhooks are not available, Gemini does offer other methods for receiving real-time data:

  1. WebSocket API: Gemini recommends using their WebSocket API to get market data and real-time information about orders and trades. This is preferred over polling REST API endpoints, which may be subject to rate limiting.

  2. Order Events: You can subscribe to order events via WebSocket to receive real-time updates on your orders.

  3. Market Data: The WebSocket API also provides real-time market data feeds.

Event Types Available

Although not webhooks, the WebSocket API allows you to subscribe to various event types:

  • subscription_ack: Acknowledges your order events subscription
  • heartbeat: Sent at five-second intervals to show your connection is alive
  • initial: List of your current active orders at the beginning of a subscription
  • accepted: Acknowledges that the exchange has received your order
  • rejected: When an order is rejected
  • booked: Your order is visible on the Gemini order book
  • fill: When an order is filled
  • cancelled: When an order is cancelled
  • cancel_rejected: When a cancellation request cannot be fulfilled
  • closed: The last event in the order lifecycle

Key Points to Consider

  1. Filtering: You can filter the events you receive based on API session keys, order event types, and symbols.

  2. Authentication: The WebSocket API requires authentication using API keys for private data.

  3. Sandbox Environment: Gemini provides a sandbox environment for testing your integrations.

  4. Rate Limiting: While not explicitly mentioned for WebSockets, be aware that REST API endpoints may have rate limits.

In conclusion, while the Gemini API doesn't offer webhooks, its WebSocket API provides a robust alternative for receiving real-time updates on various events related to orders, trades, and market data.

Rate Limits and other limitations

Here are the key points about the API Rate Limits for the Gemini API:

Rate Limits for Different Models

  1. Gemini 1.5 Pro:

    • Free tier: 2 requests per minute (RPM), 32,000 tokens per minute (TPM), 50 requests per day (RPD)
    • Pay-as-you-go tier: 360 RPM, 2 million TPM, 10,000 RPD
  2. Gemini 1.5 Flash:

    • Free tier: 15 RPM, 1 million TPM, 1,500 RPD
    • Pay-as-you-go tier: 1,000 RPM, 2 million TPM (no daily limit specified)
  3. Gemini 1.0 Pro:

    • Free tier: 15 RPM, 32,000 TPM, 1,500 RPD
    • Pay-as-you-go tier: 360 RPM, 120,000 TPM, 30,000 RPD
  4. Text Embedding Model (models/text-embedding-004):

    • 1,500 requests per minute

Key Considerations

  • The rate limits vary significantly between the free tier and pay-as-you-go tier for each model.
  • Gemini 1.5 Flash has been specifically designed for high-volume tasks and offers the highest rate limits among the models.
  • The rate limit for Gemini 1.5 Flash has been increased to 1000 RPM, and the daily limit has been removed for the pay-as-you-go tier.
  • Developers can unlock higher API rate limits by enabling a billing account in Google AI Studio.

Additional Information

  • Tuning support for Gemini 1.5 Flash will be rolled out in the coming weeks, which will be available in both Google AI Studio and the Gemini API.
  • Currently, tuning jobs are free of charge, and using a tuned model does not incur additional per-token costs.
  • For developers looking to scale with enterprise-grade features, the same models are available via Vertex AI.

Best Practices

  • Consider upgrading to the pay-as-you-go tier if you need higher rate limits for your application.
  • Monitor your usage to ensure you stay within the rate limits for your chosen tier.
  • If you need even higher limits, especially for Gemini 1.5 Pro, reach out to Google AI support for potential accommodations.
  • Keep an eye on upcoming features like tuning support for Gemini 1.5 Flash, which may offer additional optimization opportunities.

Latest API Version

Based on the search results provided, here's the most up-to-date information about the Gemini API:

The most recent version of the Gemini API is Gemini 1.5 Pro and Gemini 1.5 Flash. Here are the key points:

Latest Versions and Availability

  1. Gemini 1.5 Pro and Gemini 1.5 Flash are the latest versions.

  2. Both models were made available in preview in more than 200 countries and territories, with general availability scheduled for June 2024.

  3. Gemini 1.5 Pro received quality improvements across key use cases such as translation, coding, and reasoning.

  4. Gemini 1.5 Flash is a smaller model optimized for narrower or high-frequency tasks where response time is critical.

Key Features

  1. Both 1.5 Pro and 1.5 Flash come with a 1 million token context window.

  2. They allow interleaving of text, images, audio, and video as inputs, making them natively multimodal.

  3. A 2 million token context window for Gemini 1.5 Pro is available in private preview. Developers can join a waitlist in Google AI Studio or Vertex AI for Google Cloud customers to access this feature.

Recent Updates and New Features

  1. New API features introduced include video frame extraction and parallel function calling.

  2. Context caching for Gemini 1.5 Pro is planned for June 2024, allowing users to send only parts of their prompt, including large files, to the model once.

  3. Pay-as-you-go pricing and increased rate limits have been introduced.

API Versions

The Gemini API is available in two versions:

  1. v1: The stable version of the API, fully supported over the lifetime of the major version.
  2. v1beta: Includes early-access features that may be under development and subject to rapid changes.

It's important to note that the Gemini API is continuously evolving, with new features and improvements being added regularly. Developers should refer to the official documentation for the most up-to-date information on available features and best practices.

How to get a Gemini developer account and API Keys?

To get a developer account for Gemini and create an API integration, here are the key steps:

  1. Create a Google AI Studio account:

  2. Get an API key:

    • In Google AI Studio, click on "Get API key"
    • Choose to create a new Google Cloud project or use an existing one
    • This will provision a Gemini API key for you
  3. Keep your API key secure:

    • Do not check the API key into source control
    • Be careful about using the key directly in client-side applications, as it risks exposure
    • Consider using API key restrictions to limit usage
  4. Start using the API:

    • You can now use this API key to make calls to the Gemini API
    • Try out the quickstarts and tutorials to get started

What can you do with the Gemini API?

Based on the search results provided, here are the key data models you can interact with using the Gemini API, along with what is possible for each:

Text-only Models

  • Gemini 1.0 Pro
    • Handles natural language tasks
    • Supports multi-turn chat with text and code
    • Enables code generation
    • Allows text-only input for tasks like text completion and summarization

Multimodal Models

  • Gemini 1.5 Pro

    • Accepts text, image, audio, video, and PDF files as input in prompts
    • Generates text or code responses
    • Supports long-context understanding with up to 1 million tokens
  • Gemini 1.0 Pro Vision

    • Handles text plus images and video as input
    • Generates text or code responses
    • Cannot be used for chat
  • Gemini 1.5 Flash

    • Supports the same input and output types as Gemini 1.5 Pro
    • Designed for high-volume, cost-effective applications

Capabilities Across Models

  • Text generation from text-only prompts
  • Text generation from multimodal prompts (for multimodal models)
  • Multi-turn conversations (chat) for most models
  • Function calling (basic and parallel)
  • JSON output (constrained schema mode) - coming soon to Vertex AI for Firebase SDKs
  • Token and billable character counting
  • System instructions

Additional Features

  • Embeddings generation for words, phrases, and sentences
  • Streamed responses for more interactive experiences
  • File API for temporarily storing media files for use in prompting

Key Points

  • Different models have varying capabilities and are suited for different use cases
  • Models are available in stable, auto-updated, and preview versions
  • The API supports multiple programming languages
  • There are input token limits and file size limitations to consider

It's important to note that the specific capabilities and limitations may vary between models and versions. Always refer to the most up-to-date documentation for the exact features and constraints of each model when implementing your solution.