Latest news
Unreal Engine Path Tracer: 5 Steps for Interior RenderingCreate and Edit Architectural Massing and Meshes with Unreal Engine Modeling ModeGrasshopper Python 3 Guide: Data Access, Type Hints, and OutputsHow to Prepare Presentations and Export Animations with SketchUp ScenesUnreal Engine UV Editor: A Step-by-Step Guide to UnwrappingUsing the Gemini API with an OpenAI-Compatible Client: Python and JavaScript GuideFinding and Fixing Problem Geometry in Rhino 8: A Practical GuideUnreal Engine Pixel Streaming Setup: Bring Your Project to the BrowserPlace Repeating Architectural Elements on Points with Blender Geometry NodesA Guide to Editing Architectural Models with Selection, History, and Blocks in Rhino 8
TutorialsOpenAIGemini APIGoogle

Using the Gemini API with an OpenAI-Compatible Client: Python and JavaScript Guide

Google’s Gemini API documentation explains how to use Python and JavaScript clients, as well as REST requests, in an OpenAI-compatible way. This guide shows how to send a first request by changing the API key and endpoint settings.

Developer working on an API connection beside a desktop model in an architecture officeAI image
Representative image, generated with AI.Image: 3dsınıfı / FCA AI

In brief

  1. The Gemini API can be used with Python and JavaScript/TypeScript OpenAI clients, as well as through REST, according to the documentation.
  2. Connecting requires a Gemini API key, the Gemini API endpoint, and a supported model name.
  3. Official examples show a chat completion request using Python, JavaScript, and cURL.
  4. Google recommends calling the Gemini API directly for those who do not use OpenAI client libraries.

What will you learn in this guide?

This tutorial covers the basic connection steps for developers who want to point their existing OpenAI-compatible client code to the Gemini API. According to Google’s documentation, Gemini models can be accessed with Python and TypeScript/JavaScript client libraries or through the REST API. For those using an existing client, the basic switch involves setting the API key, request URL, and model name.

The examples use a chat completion request. Architecture and interior design teams can consider this basic connection pattern as part of an application for working with project descriptions, design notes, or questions about visual presentations. However, this guide only shows how to connect to the API; it does not provide integration with specific architectural software, guarantee the accuracy of model outputs, or offer a plugin for a design-specific workflow.

Requirements: key, client, and model

Before you begin, you’ll need a Gemini API key from Google AI Studio. Google’s documentation provides examples for OpenAI client libraries in Python and JavaScript/TypeScript, as well as REST requests. The code examples use the model name gemini-3.8-flash; if you choose a different compatible model, update the model field accordingly. The source does not provide the client library’s version number or pricing information.

For those who do not yet use OpenAI client libraries, Google recommends calling the Gemini API directly. So, if you have an existing application, first check whether the client you use is suitable for this approach. If you’re building a new application, consider whether calling the API directly meets your requirements. In the examples below, GEMINI_API_KEY is a placeholder; replace it with your actual key.

Step by step: send your first request

  1. Get an API key. Get a Gemini API key from Google AI Studio. The key is used to authenticate requests; the examples use a placeholder, not an actual key.

  2. Point the client to the Gemini endpoint. In the Python example, base_url points to the Gemini API address; in the JavaScript example, the field is baseURL. This setting sends the client’s requests to the documented Gemini address instead of its default address.

  3. Specify the model name. The example uses gemini-3.8-flash. The model name is a separate field in the request; if you use another model, make sure this field matches your choice.

  4. Run your first text request. The Python example below sends system and user messages in a chat completion request and prints the message in the response. The code is taken from Google’s openly licensed guide.

python
from openai import OpenAI
client = OpenAI(
api_key="GEMINI_API_KEY",
base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
)
response = client.chat.completions.create(
model="gemini-3.8-flash",
messages=[
{ "role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Explain to me how AI works"
}
]
)
print(response.choices[0].message)

The user message in the example asks for a general explanation. In an architecture-focused application, you could replace it with content suited to the application’s purpose, such as a request to summarize a project note. This is an adaptation of how the code is used; it does not mean the source guarantees results for a specific architectural task.

  1. Set up the same basic connection with JavaScript. The JavaScript example also defines the API key, endpoint, model, and messages. Once the request completes, the returned message is printed to the console.

javascript
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "GEMINI_API_KEY",
baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/"
});
const response = await openai.chat.completions.create({
model: "gemini-3.8-flash",
messages: [
{ role: "system",
content: "You are a helpful assistant."
},
{
role: "user",
content: "Explain to me how AI works",
},
],
});
console.log(response.choices[0].message);
  1. Send a REST request without a client. The cURL example below performs the same basic operation with an HTTP request. The key goes in the Authorization header, while the model and message are in the request body.

bash
curl "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GEMINI_API_KEY" \
-d '{
"model": "gemini-3.8-flash",
"messages": [
{
"role": "user",
"content": "Explain to me how AI works"
}
]
}'

The key point shared by all three methods is to direct the request to the Gemini API and use the correct key and model name. Google summarizes the switch to compatible clients as changing settings in three lines; this describes the basic connection settings and does not mean that every application will require no other code changes.

Common errors and checkpoints

  • Leaving the default endpoint in place: If the client is not pointed to the Gemini API, the request may not go to the expected address. Check the base_url setting in Python, baseURL in JavaScript, and the REST address.

  • Not replacing the placeholder: GEMINI_API_KEY in the examples is not an actual key. Replace it with the value obtained from Google AI Studio.

  • Misspelling the model name: The examples show gemini-3.8-flash in the model field. Make sure the value in the request matches the name of the model you selected.

  • Assuming compatibility is identical across all features: The guide also covers topics such as streaming responses, function calling, and image understanding, in addition to chat completion. However, each may have a different request format and configuration; the basic chat example here does not cover all setup details for these features.

  • Using thinking settings together: The documentation notes that reasoning_effort overlaps in function with Gemini-specific thinking_level or thinking_budget settings, and that they should not be used at the same time. When adding advanced thinking settings, also check the documentation for the relevant model.

For architecture, interior design, and archviz workflows, this approach can be a starting point for developers who want to try text-based API access through an existing client. Ideas such as adding text requests about project descriptions or design notes to an in-house tool can be tested; however, the source does not specify compatibility with particular software, image-generation workflows, or local hardware requirements. Before moving to production, separately assess licensing and API costs, the terms for the model you use, and data flows within the application; the source text provides no pricing or hardware information.

Next steps

After your first text request works, you can explore the sections on streaming responses, function calling, and image understanding in the same Google document. These are not ready-made features that have been added directly to the basic chat example; each should be considered in terms of its own request format and requirements. If your application does not already use the OpenAI client library, calling the Gemini API directly should also be part of your initial decision.

For architecture teams, the safest way to experiment is to first build a small prototype with non-sensitive sample project text and treat the returned output as supporting material to review, not as a replacement for design decisions. This recommendation does not claim that the API guarantees a particular design outcome; it is a practical approach to establishing your team’s own validation process before bringing the technical connection into a real workflow.

Source and license

This tutorial has been adapted into Turkish from the Python, JavaScript, and REST examples in Google’s Gemini API “OpenAI compatibility” guide. The source is licensed under CC BY 4.0.

Sources

1 source
A(
ai.google.dev (CC BY 4.0)ai.google.dev/gemini-api/docs/openai.md.txt
Summary

Source texts are not republished; short quotes are marked, everything else is our own summary and commentary.

3dsınıfı’s take
3dEditor’s assessment

For architecture and visualization offices in Turkey, the practical value of this approach is that it offers an option for directing existing OpenAI-compatible client code to the Gemini API. Small text-based prototypes can be a good starting point for learning how to add an API connection to an in-house tool; however, the guide does not provide integration with specific design software.

Before making a decision, separately check API usage costs, licensing terms, and how the application used by your team handles data. Since the source does not specify pricing or local hardware requirements, it would be wrong to make assumptions about these. In particular, when moving to production, test features and compatibility beyond the sample code separately.

Frequently asked questions

Can the Gemini API be used with the OpenAI client library?

According to Google’s documentation, Gemini models can be accessed using OpenAI client libraries for Python and JavaScript/TypeScript. Set the request URL, API key, and model name for the Gemini API.

Where can I get a Gemini API key?

The documentation says that a Gemini API key can be obtained from Google AI Studio.

Can I send requests to the Gemini API without using an OpenAI client?

Yes. Google’s guide also provides a REST API example and recommends calling the Gemini API directly for those who do not use OpenAI client libraries.

Comments and the forum are in Turkish.Join the discussion
+

Related news