Skip to main content
Google Gemini is a very powerful AI conversation system that can generate smooth and natural replies in just a few seconds by inputting prompts. Gemini provides amazing intelligent assistance, greatly enhancing human work efficiency and creativity. This document mainly describes the usage process of the Gemini Chat Completion API, allowing us to easily utilize the official Gemini conversation features.

Application Process

To use Gemini Chat Completion API, first open the Ace Data Cloud Console and copy your API Token. If you are not logged in, you will be redirected to sign in and brought back to this page automatically. A single API Token works across every service on the platform — no need to subscribe per service. New accounts receive free starter credit; when it runs low you can top up your shared balance in the console.
📘 Full documentation: Gemini Chat Completion API →

Basic Usage

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

When using this interface for the first time, we need to fill in at least three pieces of information: one is authorization, which can be selected directly from the dropdown list. The other parameter is model, which is the category of the Gemini official model we choose to use. Here we mainly have 6 types of models; details can be found in the models we provide. The last parameter is messages, which is an array of the questions we input. It is an array that allows multiple questions to be uploaded simultaneously, with each question containing role and content. The role indicates the role of the questioner, and we provide three identities: user, assistant, and system. The other content is the specific content of our question. You can also notice that there is corresponding code generation on the right side; you can copy the code to run directly or click the “Try” button for testing.

After the call, we find that the returned result is as follows:
The returned result contains multiple fields, described as follows:
  • id, the ID generated for this conversation task, used to uniquely identify this conversation task.
  • model, the selected Gemini official model.
  • choices, the response information provided by Gemini for the question.
  • usage: statistics on the tokens for this Q&A.
Among them, choices contains the response information from Gemini, and the choices inside it shows the specific information of Gemini’s response, as can be seen in the figure.

It can be seen that the content field in choices contains the specific content of Gemini’s reply.

Streaming Response

This interface also supports streaming responses, which is very useful for web integration, allowing the webpage to display results word by word. If you want to return responses in a streaming manner, you can change the stream parameter in the request header to true. Modify as shown in the figure, but the calling code needs to have corresponding changes to support streaming responses.

After changing stream to true, the API will return the corresponding JSON data line by line, and we need to make corresponding modifications at the code level to obtain line-by-line results. Python sample calling code:
The output effect is as follows:
It can be seen that there are many data in the response, and the choices in data are the latest response content, consistent with the content introduced above. The choices are the newly added response content, which you can integrate into your system based on the results. The end of the streaming response is determined by the content of data; if the content is [DONE], it indicates that the streaming response has completely ended. The returned data result has multiple fields, described as follows:
  • id, the ID generated for this dialogue task, used to uniquely identify this dialogue task.
  • model, the selected Gemini official model.
  • choices, the response information provided by Gemini for the query.
JavaScript is also supported, for example, the streaming call code for Node.js is as follows:
Java sample code:
Other languages can be rewritten accordingly; the principle is the same.

Multi-turn Dialogue

If you want to integrate multi-turn dialogue functionality, you need to upload multiple queries in the messages field. The specific examples of multiple queries are shown in the image below:

Python sample call code:
By uploading multiple queries, you can easily achieve multi-turn dialogue and obtain responses as follows:
It can be seen that the information contained in choices is consistent with the basic usage content, which includes the specific content of responses from Gemini to multiple dialogues, allowing for answers to corresponding questions based on multiple dialogue contents.

Gemini-3.0 Multimodal Model

Request example:
Example result:
Of course, you can also submit a video link, with the specific input as follows:
Example result:
It can be seen from the above that the Gemini 3.0 model supports multimodal understanding.

Gemini-3.1 Multimodal Model

Gemini 3.1 Pro is an upgraded version of Gemini 3.0 Pro, with the underlying model being gemini-3.1-pro-preview, also supporting multimodal inputs such as text, images, and videos, with stronger reasoning and understanding capabilities. The usage is completely consistent with Gemini 3.0 Pro; just replace the model parameter with gemini-3.1-pro. Request example:
Gemini 3.1 Pro also supports video understanding:
The return format is consistent with Gemini 3.0 Pro, as detailed in the description of the Gemini-3.0 multimodal model section above.

Error Handling

When calling the API, if an error occurs, 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 chat functionality using the Gemini Chat Completion API. We hope this document helps you better integrate and use the API. If you have any questions, please feel free to contact our technical support team.