Skip to main content

What you will build

You will send a native Gemini POST /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:
https://api.cometapi.com/v1beta/models/{model}:generateContent
Use x-goog-api-key for direct native Gemini HTTP requests:
x-goog-api-key: $COMETAPI_KEY
Use the OpenAI-compatible base URL only when your application already uses Chat Completions:
https://api.cometapi.com/v1

Native Gemini format

Native Gemini requests use contents, 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.
curl "https://api.cometapi.com/v1beta/models/your-gemini-model-id:generateContent" \
  -H "x-goog-api-key: $COMETAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "text": "Explain why base URL configuration matters."
          }
        ]
      }
    ],
    "generationConfig": {
      "temperature": 0.3
    }
  }'

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.
curl https://api.cometapi.com/v1/chat/completions \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-gemini-model-id",
    "messages": [
      {
        "role": "user",
        "content": "Explain why base URL configuration matters."
      }
    ]
  }'

Flow explanation

PathEndpointRequest shapeSDKUse when
Gemini nativePOST /v1beta/models/\{model\}:generateContentcontents, parts, generationConfigGoogle GenAI SDK or direct HTTPYou need Gemini-specific fields, multimodal parts, thinking controls, grounding, or native streaming.
OpenAI-compatiblePOST /v1/chat/completionsmessages, temperature, max_completion_tokensOpenAI SDK or direct HTTPYour app already uses Chat Completions and only needs a Gemini text model behind that shape.
Do not mix the two request formats. Native Gemini fields such as contents and generationConfig belong on the generateContent route. Chat Completions fields such as messages belong on the OpenAI-compatible route.

Troubleshooting / FAQ

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.
Send contents, parts, generationConfig, and streamGenerateContent requests to the Gemini native endpoint. The OpenAI-compatible route expects messages and Chat Completions parameters.
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.
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