Generate Content
curl --request POST \
--url https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Write a short haiku about the ocean."
}
]
}
]
}
'import requests
url = "https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent"
payload = { "contents": [
{
"role": "user",
"parts": [{ "text": "Write a short haiku about the ocean." }]
}
] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
contents: [{role: 'user', parts: [{text: 'Write a short haiku about the ocean.'}]}]
})
};
fetch('https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'contents' => [
[
'role' => 'user',
'parts' => [
[
'text' => 'Write a short haiku about the ocean.'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short haiku about the ocean.\"\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short haiku about the ocean.\"\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short haiku about the ocean.\"\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"candidates": [
{
"content": {},
"finishReason": "<string>"
}
],
"usageMetadata": {}
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Invalid request"
}
}Completion API
Google Completion API
Generate text with Google Gemini models through Langdock’s public API. Supports normal and streaming completions and is fully compatible with the official Vertex AI SDKs (Python / Node).
POST
/
google
/
{region}
/
v1beta
/
models
/
{model}
:generateContent
Generate Content
curl --request POST \
--url https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Write a short haiku about the ocean."
}
]
}
]
}
'import requests
url = "https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent"
payload = { "contents": [
{
"role": "user",
"parts": [{ "text": "Write a short haiku about the ocean." }]
}
] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
contents: [{role: 'user', parts: [{text: 'Write a short haiku about the ocean.'}]}]
})
};
fetch('https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'contents' => [
[
'role' => 'user',
'parts' => [
[
'text' => 'Write a short haiku about the ocean.'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent"
payload := strings.NewReader("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short haiku about the ocean.\"\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short haiku about the ocean.\"\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"Write a short haiku about the ocean.\"\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"candidates": [
{
"content": {},
"finishReason": "<string>"
}
],
"usageMetadata": {}
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Invalid request"
}
}Google Completion Endpoint (v1beta)
Before You Start
- API key: To use the API, create a personal API key or ask your workspace admin for a workspace API key with the Completion API scope.
Base URL
https://api.langdock.com/google/{region}/v1beta/models/{model}:generateContent
Dedicated deploymentsReplace
api.langdock.com with <your-deployment-url>/api/public in all requests.How It Works
This endpoint exposes Google Gemini models that are hosted in Google Vertex AI.It mirrors the structure of the official Vertex generateContent API. To use it, you need to:
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 normal calls or consume the SSE events for streaming.
eu or us)• Optional Server-Sent Event (SSE) streaming with the same event labels used by the Google Python SDK (
message_start, message_delta, message_stop)• A models discovery endpoint
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
curl -H "x-api-key: $LD_API_KEY" \
https://api.langdock.com/google/eu/v1beta/models
curl -H "x-goog-api-key: $LD_API_KEY" \
https://api.langdock.com/google/eu/v1beta/models
1. List available models
GET /{region}/v1beta/models
region must be eu or us.
Successful response
array
List of objects with the following shape:
- name – Fully-qualified model name (e.g.
models/gemini-2.5-flash). - supportedGenerationMethods – Always
["generateContent", "streamGenerateContent"].
curl -H "Authorization: Bearer $LD_API_KEY" \
https://api.langdock.com/google/eu/v1beta/models
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 to use streaming or not.
Example path: google/eu/v1beta/models/gemini-2.5-flash:streamGenerateContent
Request body
The request body follows the officialGenerateContentRequest structure.
Required fields
contents (Content[], required)Conversation history. Each object has a role (string) and parts array containing objects with text (string).
"contents": [
{
"role": "user",
"parts": [
{
"text": "What's the weather like?"
}
]
}
]
functionCall and functionResponse objects for function calling. When you use a Gemini 3 model, return the thoughtSignature (and function-call id) from the model’s functionCall part unchanged in your next request. The official SDKs do this for you; if you build requests by hand, copy the fields as-is.
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 parametercandidateCount(number): Number of response candidates to generatemaxOutputTokens(number): Maximum number of tokens to generatestopSequences(string[]): Sequences that will stop generationresponseMimeType(string): MIME type of the responseresponseSchema(object): Schema for structured output
"generationConfig": {
"temperature": 0.7,
"topP": 0.9,
"topK": 40,
"maxOutputTokens": 1000,
"stopSequences": ["END", "STOP"]
}
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”)
"safetySettings": [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
}
]
tools (Tool[], optional)Array of tool objects for function calling. Each tool contains
functionDeclarations array with:
name(string): Function namedescription(string): Function descriptionparameters(object): JSON schema defining function parameters
"tools": [
{
"functionDeclarations": [
{
"name": "get_weather",
"description": "Get current weather information",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name"
}
}
}
}
]
}
]
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
"toolConfig": {
"functionCallingConfig": {
"mode": "ANY",
"allowedFunctionNames": ["get_weather"]
}
}
systemInstruction (string | Content, optional)System instruction to guide the model’s behavior. Can be a string or Content object with role and parts.
"systemInstruction": {
"role": "system",
"parts": [
{
"text": "You are a weather agent. Use the weather tool when asked about weather."
}
]
}
If
toolConfig.functionCallingConfig.allowedFunctionNames is provided, mode must be ANY.Minimal example
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $LD_API_KEY" \
https://api.langdock.com/google/us/v1beta/models/gemini-2.5-pro:generateContent \
-d '{
"contents": [{
"role": "user",
"parts": [{"text": "Write a short poem about the ocean."}]
}]
}'
Streaming
When action isstreamGenerateContent the endpoint returns an
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:
event: message_delta
data: {
"candidates": [
{
"index": 0,
"content": {
"role": "model",
"parts": [{ "text": "The ocean whispers..." }]
}
}
]
}
import google.generativeai as genai
def get_current_weather(location):
"""Get the current weather in a given location"""
return f"The current weather in {location} is sunny with a temperature of 70 degrees and a wind speed of 5 mph."
genai.configure(
api_key="<YOUR_LANGDOCK_API_KEY>",
transport="rest",
client_options={"api_endpoint": "https://api.langdock.com/google/<REGION>/"},
)
model = genai.GenerativeModel("gemini-2.5-flash", tools=[get_current_weather])
response = model.generate_content(
"Please tell me the weather in San Francisco, then tell me a story on the history of the city"
)
print(response)
model = genai.GenerativeModel("gemini-2.5-flash")
response = model.generate_content(
"Tell me an elaborate story on the history of the city of San Francisco",
stream=True,
)
for chunk in response:
if chunk.text:
print(chunk.text)
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.
Langdock intentionally blocks browser-origin requests to protect your API key and ensure your applications remain secure. For more information, please see our guide on API Key Best Practices.
Authorizations
API key as Bearer token. Format "Bearer YOUR_API_KEY"
Path Parameters
The region of the API to use.
Available options:
eu, us The model ID (e.g., gemini-2.5-pro, gemini-2.5-flash).
Body
application/json
Conversation history. Parts may be text, functionCall, or functionResponse.
Show child attributes
Show child attributes
Was this page helpful?