Skip to main content
Google Gemini is a very powerful AI conversational system. Simply by entering a prompt, it can generate fluent and natural responses in just a few seconds. Gemini can provide astonishing intelligent assistance, greatly improving human work efficiency and creativity. This document mainly introduces the usage process of Gemini Chat Completion API operations. With it, we can easily use the official Gemini conversational functionality.

Application Process

To use the Gemini Chat Completion API, first go to the Ace Data Cloud Console to obtain your API Token and keep it for later use. If you have not logged in or registered yet, you will be automatically redirected to the login page to register and log in. After completion, you will automatically return to the current page. One API Token can call all platform services; there is no need to apply separately for each service. Your first application will include free credits for a free trial; when credits are insufficient, you can top up your general balance in the console.
📘 Complete documentation: Gemini Chat Completion API →

Basic Usage

Next, you can fill in the corresponding content in the interface, as shown in the image:

When using this API for the first time, we need to fill in at least three items. One is authorization, which can be selected directly from the dropdown list. Another parameter is model; model is the category of official Gemini model we choose to use, and the available models are subject to the model enumeration in the API documentation. The final parameter is messages; messages is the array of prompts we enter. It is an array, indicating that multiple prompts can be uploaded at the same time. Each prompt contains role and content, where role represents the role of the questioner. We provide three identities: user, assistant, and system. The other field, content, is the specific content of our question. At the same time, you can notice that the corresponding invocation code is generated on the right. You can copy the code and run it directly, or click the “Try” button directly for testing.

Tip: Flash models in the gemini-3.x series are reasoning models and will consume reasoning tokens first; please set max_tokens above 512, otherwise only empty content may be returned. gemini-3.8-flash is the currently recommended Flash model, supporting up to 1 million Token context, image input, tool calling, and streaming responses; it is currently called through the Chat Completions API.
After calling it, we find that the returned result is as follows:
The returned result contains multiple fields, introduced as follows:
  • id, the ID generated for this conversation task, used to uniquely identify this conversation task.
  • model, the selected official Gemini model.
  • choices, the response information provided by Gemini for the prompt.
  • usage: statistical information about tokens for this Q&A session.
Among them, choices contains Gemini’s response information, and the choices inside it contains the specific information of Gemini’s response, as shown in the image.

As you can see, the content field in choices contains the specific content of Gemini’s response.

Image Understanding (Multimodal Input)

Gemini is a native multimodal model and can directly “view images”. To pass in an image, change the content of a message from a string to a content block array, and place both text blocks and image_url blocks in the array—this is fully consistent with OpenAI and the official Gemini OpenAI-compatible format. image_url.url supports two formats:
  • base64 data: URI (recommended, most stable): The format is data:<media type>;base64,<data>, for example, data:image/jpeg;base64,/9j/4AAQ.... The media type (MIME) is already written in the data: prefix, so there is no need for, nor is there, a separate media_type field.
  • Publicly accessible image URL: For example, https://cdn.acedata.cloud/4hfydw.jpg.
Supported image types: png, jpeg, webp, heic, heif. Python sample invocation code (base64 data URI):
You can also directly pass a publicly accessible image URL:
💡 image_url only accepts the url field (the value can be an image URL or a base64 data: URI), as well as the optional detail field. Do not pass media_type—that is the image field for Anthropic Claude and does not belong to the OpenAI / Gemini image_url format.

Streaming Response

This API also supports streaming responses, which is very useful for web integration and allows webpages to achieve a word-by-word display effect. If you want to return responses in a stream, you can change the stream parameter in the request header to true. Make the modification as shown in the image, but the calling code needs corresponding changes to support streaming responses.

After changing stream to true, the API will return the corresponding JSON data line by line. At the code level, we need to make corresponding changes to obtain the line-by-line results. Python sample calling code:
The output is as follows:
As you can see, there are many data entries in the response, and the choices within data are the latest response content, consistent with the content introduced above. choices contains the newly added response content, which you can use to integrate with your system based on the results. At the same time, the end of a streaming response is determined based on the content of data. If the content is [DONE], it means that the streaming response has completely ended. The returned data result contains multiple fields, introduced as follows:
  • id, generates the ID for this conversation task, used to uniquely identify this conversation task.
  • model , the selected Gemini official website model.
  • choices, the response information provided by Gemini for the prompt.
JavaScript is also supported, for example, the Node.js streaming call code is as follows:
Java sample code:
Other languages can be adapted separately; the principle is the same.

Multi-turn Conversations

If you want to integrate multi-turn conversation functionality, you need to upload multiple prompts in the messages field. A specific example of multiple prompts is shown in the image below:

Python sample call code:
By uploading multiple prompts, you can easily implement multi-turn conversations and obtain the following response:
As can be seen, the information contained in choices is consistent with the basic usage content. This contains the specific content of Gemini’s replies to multiple conversations, so it can answer the corresponding questions based on multiple conversation contents.

Gemini-3.0 Multimodal Model

Request example:
Example result:
Of course, you can also provide a video link. The specific input is as follows:
Sample result:
As can be seen from the above, the Gemini 3.0 model can support multimodal understanding.

Gemini-3.1 Multimodal Model

gemini-3.1-pro-preview is the official model ID for the current Gemini 3.1 Pro. It supports multimodal inputs such as text, images, and videos, and is suitable for complex reasoning, coding, and understanding tasks. Request example:
Gemini 3.1 Pro also supports video understanding:
The return format is consistent with Gemini 3.0 Pro. For details, see the description in the Gemini-3.0 multimodal model section above.

Error Handling

When calling the API, if an error is encountered, the API will return the corresponding error code and message. For example:
  • 400 token_mismatched: Bad request, possibly due to missing or invalid parameters.
  • 400 api_not_implemented: Bad request, possibly due to missing or invalid parameters.
  • 401 invalid_token: Unauthorized, invalid or missing authorization token.
  • 429 too_many_requests: Too many requests, you have exceeded the rate limit.
  • 500 api_error: Internal server error, something went wrong on the server.

Error Response Example

Conclusion

Through this document, you have learned how to easily implement the official Gemini conversation functionality using the Gemini Chat Completion API. We hope this document can help you better integrate and use this API. If you have any questions, please feel free to contact our technical support team.