Google Completion API

This endpoint exposes Google Gemini models that are hosted in Google Vertex AI. It mirrors the structure of the official Vertex generateContent API.

Features

  • Region selection (eu or us)

  • Optional Server-Sent Event (SSE) streaming with compatible event labels used by the Google Python SDK (message_start, message_delta, message_stop)

  • A models discovery endpoint

1

Get available models

Call GET /{region}/v1beta/models/ to retrieve the list of Gemini models.

2

Pick a model & action

Choose a model ID and decide between generateContent or streamGenerateContent.

3

Send your request

POST to /{region}/v1beta/models/{model}:{action} with your prompt in contents.

4

Handle the response

Parse the JSON response for non-streaming calls or consume the SSE events for streaming.


Base URL

https://api.langdock.com/google/{region}

In dedicated deployments, api.langdock.com maps to /api/public


Authentication

Send one of the following headers while using the Langdock API Key. All headers are treated identically. Missing or invalid keys return 401 Unauthorized.

Authorization header example:

curl -H "Authorization: Bearer $LD_API_KEY" \
     https://api.langdock.com/google/eu/v1beta/models

x-api-key header example:

x-goog-api-key header example:


1. List available models

GET /{region}/v1beta/models

region must be eu or us.

Successful response: an array of model objects with the following shape:

  • name – Fully-qualified model name (e.g. models/gemini-2.5-flash)

  • displayName – Human-readable name shown in the Langdock UI

  • supportedGenerationMethods – Always ["generateContent", "streamGenerateContent"]

Example:


2. Generate content

POST /{region}/v1beta/models/{model}:{action}

  • model – The model ID as returned by the models endpoint (without the models/ prefix).

  • action – generateContent or streamGenerateContent depending on whether you want streaming or not.

Example path:

Request body

The request body follows the official GenerateContentRequest structure.

Required fields

  • contents (Content[], required) Conversation history. Each object has a role (string) and parts array containing objects with text (string).

Example:

  • model (string, required) The model to use for generation (e.g., gemini-2.5-pro, gemini-2.5-flash).

Optional fields

  • generationConfig (object, optional) Configuration for text generation. Supported fields:

    • temperature (number): Controls randomness (0.0-2.0)

    • topP (number): Nucleus sampling parameter (0.0-1.0)

    • topK (number): Top-k sampling parameter

    • candidateCount (number): Number of response candidates to generate

    • maxOutputTokens (number): Maximum number of tokens to generate

    • stopSequences (string[]): Sequences that will stop generation

    • responseMimeType (string): MIME type of the response

    • responseSchema (object): Schema for structured output

Example:

  • safetySettings (SafetySetting[], optional) Array of safety setting objects. Each object contains:

    • category (string): The harm category (e.g., HARM_CATEGORY_HARASSMENT)

    • threshold (string): The blocking threshold (e.g., BLOCK_MEDIUM_AND_ABOVE)

Example:

  • tools (Tool[], optional) Array of tool objects for function calling. Each tool contains functionDeclarations array with:

    • name (string): Function name

    • description (string): Function description

    • parameters (object): JSON schema defining function parameters

Example:

  • toolConfig (object, optional) Configuration for function calling. Contains functionCallingConfig with:

    • mode (string): Function calling mode (ANY, AUTO, NONE)

    • allowedFunctionNames (string[]): Array of allowed function names

Example:

  • systemInstruction (string | Content, optional) System instruction to guide the model’s behavior. Can be a string or Content object with role and parts.

Example:

Note: If toolConfig.functionCallingConfig.allowedFunctionNames is provided, mode must be ANY.

Minimal example

Streaming

When action is streamGenerateContent the endpoint returns a text/event-stream with compatible events:

  • message_start – first chunk that contains content

  • message_delta – subsequent chunks

  • message_stop – last chunk (contains finishReason and usage metadata)

Example message_delta event:

Python SDK example with function calling:

Python SDK streaming example:


Using Google-compatible libraries

The endpoint is fully compatible with official Google SDKs including the Vertex AI Node SDK (@google-cloud/vertexai), Google Generative AI Python library (google-generative-ai), and the Vercel AI SDK for edge streaming.

Headers

  • Authorization (string, required): API key as Bearer token. Format "Bearer YOUR_API_KEY"

Path Parameters

  • region (enum, required): The region of the API to use. Available options: eu, us

  • model (string, required): The model ID (e.g., gemini-2.5-pro, gemini-2.5-flash)

Body (application/json)

  • contents (object[]): required. The content to generate a response for.

    • role (enum): user or model

    • parts (object[])

Response (200 application/json)

  • candidates (object[])

    • content (object)

    • finishReason (string)

    • usageMetadata (object)