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 conversational capabilities of official Gemini.

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 yet logged in or registered, you will be automatically redirected to the login page, where you will be invited 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 includes free credits for a free trial; when your credits are insufficient, you can top up your general balance in the Console.
📘 Full documentation: Gemini Chat Completion API →

Basic Usage

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

When using this API for the first time, we need to fill in at least three items. One is authorization, which can be directly selected from the dropdown list. Another parameter is model; model is the category of Gemini official model we choose to use. The available models are subject to the model enumeration in the API documentation. The last parameter is messages; messages is the array of prompt text we enter. It is an array, indicating that multiple prompt texts 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: The flash models in the gemini-3.x series are reasoning models and will consume reasoning tokens first; please set max_tokens to 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.
gemini-4-argon can also be used for Chat Completions and supports regular and streaming text responses. It may allocate part of the output budget to reasoning; for complex tasks, please leave sufficient space for max_tokens. Google recommends at least 32768 for regular tasks with this model. Do not equate this API with the backend long-output capability of the Google Interactions API. After calling it, 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 prompt.
  • usage : statistical information about tokens for this Q&A session.
Among them, choices contains Gemini’s response information, and the choices within it contains the specific information of Gemini’s response, as shown in the figure.

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

Image Understanding (Multimodal Input)

Gemini is a natively multimodal model and can directly “see images.” To pass 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 OpenAI-compatible format of official Gemini. 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 calling 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 Anthropic Claude’s image field and does not belong to the OpenAI / Gemini image_url format.

Streaming Response

This API also supports streaming responses, which are very useful for web integration and can enable a word-by-word display effect on web pages. If you want to return responses in a stream, you can change the stream parameter in the request header to true. Modify it as shown in the image; however, 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. The choices inside 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 result. At the same time, the end of the 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, the ID generated 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 streaming invocation code for Node.js is as follows:
Java sample code:
Other languages can be adapted separately. The principle is the same.

Multi-turn Conversation

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 invocation code:
By uploading multiple prompts, you can easily implement multi-turn conversations and obtain the following response:
As you can see, the information contained in choices is consistent with the basic usage content. This contains the specific content of Gemini’s responses to multiple conversations, so corresponding questions can be answered based on multiple conversation contents.

Gemini-3.0 Multimodal Model

Request example:
Example result:
Of course, you can also pass a video link. The specific input is as follows:
Sample result:
As can be seen above, the Gemini 3.0 model supports 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.