What you will build
You will send a native GeminiPOST /v1beta/models/\{model\}:generateContent request, then compare it with the OpenAI-compatible POST /v1/chat/completions option for apps that already use Chat Completions request shapes.
Prerequisites
- A CometAPI API key stored in
COMETAPI_KEY - A Gemini text model ID from the Models page
curl, Python 3.10+, or Node.js 18+
API key, base URL, authentication
Use the Gemini native endpoint when you want Gemini request fields:x-goog-api-key for direct native Gemini HTTP requests:
Native Gemini format
Native Gemini requests usecontents, parts, and generationConfig. Use this path when you need Gemini-specific fields such as thinking controls, media parts, Google Search grounding, or native streaming operators.
OpenAI-compatible option
Use the OpenAI-compatible route when you are migrating an existing OpenAI SDK or Chat Completions app and do not need Gemini native request fields.Flow explanation
| Path | Endpoint | Request shape | SDK | Use when |
|---|---|---|---|---|
| Gemini native | POST /v1beta/models/\{model\}:generateContent | contents, parts, generationConfig | Google GenAI SDK or direct HTTP | You need Gemini-specific fields, multimodal parts, thinking controls, grounding, or native streaming. |
| OpenAI-compatible | POST /v1/chat/completions | messages, temperature, max_completion_tokens | OpenAI SDK or direct HTTP | Your app already uses Chat Completions and only needs a Gemini text model behind that shape. |
contents and generationConfig belong on the generateContent route. Chat Completions fields such as messages belong on the OpenAI-compatible route.
Troubleshooting / FAQ
Which path should I start with
Which path should I start with
Start with native Gemini
generateContent when you are building a new Gemini workflow. Use the OpenAI-compatible route when an existing app already depends on OpenAI SDK or Chat Completions request shapes.Native Gemini fields fail on Chat Completions
Native Gemini fields fail on Chat Completions
Send
contents, parts, generationConfig, and streamGenerateContent requests to the Gemini native endpoint. The OpenAI-compatible route expects messages and Chat Completions parameters.The Gemini model ID fails
The Gemini model ID fails
Confirm that the model ID is available to your account and supports the route you are calling. Use the Models page to find current model IDs.
The SDK points to the wrong service
The SDK points to the wrong service
For Google GenAI SDK requests, set the base URL to
https://api.cometapi.com. For OpenAI SDK requests, set base_url in Python or baseURL in Node.js to https://api.cometapi.com/v1.Next steps
- Use the Gemini native API reference for full
generateContentrequest and response fields. - Read the Chat Completions API reference for the OpenAI-compatible request shape.
- Configure OpenAI SDK clients in Use CometAPI with OpenAI SDKs.
- List available models with List available CometAPI models.
- Add retry and rate-limit handling with Error codes and retry strategy.