Appearance
Gemma 4 31B ​
Overview ​
Gemma 4 31B is a powerful multimodal reasoning model from Google with advanced capabilities for text and image understanding. The model identifier is google/gemma-4-31b-it and supports a native context length of up to 256,000 tokens. It is designed for multimodal reasoning, visual question answering, coding assistance, tool calling, and long-context analysis.
Supported languages: Multilingual
Input: Multilingual text, image
Output: Multilingual text, code, tool calls
Note
- Thinking mode is disabled by default.
- To enable thinking, set
reasoning_effortto a supported value other than"none", such as"high". Settingchat_template_kwargs.enable_thinkingtotruealso works but is not required when usingreasoning_effort. - When thinking is enabled, the response includes a separate
reasoningfield with the step-by-step thought process. - This page documents the features currently exposed on Swisscom Inference Endpoints.
Use Cases: Applications that require multimodal reasoning, visual question answering, coding assistance, tool calling, structured workflows, and long-context analysis.
Model Card: Gemma 4 31B
Key Capabilities ​
- Native System Role Support: Developer-provided instructions that the model follows regardless of user messages.
- Multimodal Input (Text + Image): Accepts text and image inputs in variable aspect ratios and resolutions. Images must be provided as base64-encoded data strings. Image token budget is configurable via
mm_processor_kwargs.max_soft_tokens. - Thinking Mode: Step-by-step reasoning capability that can be enabled per request. When enabled, the model provides detailed reasoning traces in a separate field.
- Function/Tool Calling: Supports function definitions with JSON Schema parameters, tool choice modes (none, auto, required, or specific function), and returns structured tool calls with ID, name, and arguments.
- Streaming Support: Server-sent events (SSE) for real-time token streaming with optional usage statistics.
Thinking Mode ​
Gemma 4 supports thinking mode for complex reasoning tasks. When enabled, the model generates step-by-step reasoning before producing the final answer.
Default behavior: Thinking is disabled. The response contains only the content field.
To enable thinking: Set the top-level request parameter reasoning_effort to a supported value other than "none", such as "low", "medium", or "high". vLLM automatically enables thinking, so chat_template_kwargs.enable_thinking: true is not required.
To disable thinking: Set reasoning_effort to "none".
Explicit override: You can still set enable_thinking in the chat_template_kwargs object. An explicitly supplied value takes priority over reasoning_effort. If neither parameter is supplied, thinking remains disabled.
See Automatic enable_thinking activation in vLLM for details.
Response with thinking enabled: The response includes both content (final answer) and reasoning (step-by-step thought process) fields.
Multimodal Reasoning ​
Gemma 4 can process image and text input in the same request. This makes the model suitable for tasks such as:
- describing scenes and visual content
- extracting information from screenshots, charts, and documents
- solving reasoning tasks that combine image and text context
- generating grounded answers based on visual evidence
Tool Calling ​
Gemma 4 is suitable for agentic workflows where the model needs to call external functions. By supplying a tools definition and setting tool_choice, applications can let the model decide when a tool should be invoked and then continue the conversation with tool results.
Best Practices ​
- For thinking mode, a temperature of
0.7is recommended for better reasoning quality. - For fast responses without thinking, use temperature between
0.3and0.5. - When image input is used, place the image before the task instruction inside the message content.
- Control image token budget via
mm_processor_kwargs.max_soft_tokens. Available values:70,140,280(default),560,1120. - Higher token budgets (560, 1120) provide better quality for OCR and detailed image analysis tasks.
- Lower token budgets (70, 140) are suitable for simple image tasks where fine details are not critical.
- In multi-turn applications with thinking enabled, it is usually preferable to keep only the final answer in the stored conversation history instead of the full reasoning trace.
- For complex reasoning and coding workloads, enable thinking mode and use a larger
max_completion_tokensbudget. - Maximum 128 tools per request.
- Maximum 4 stop sequences.
Endpoints ​
1. Create Chat Completion ​
POST /v1/chat/completions
Description ​
Generates a chat completion for text-only, multimodal, or tool-calling requests.
Request Body ​
json
{
"model": "google/gemma-4-31b-it",
"messages": [
{
"role": "user",
"content": "Summarize the main differences between retrieval and fine-tuning."
}
],
"temperature": 0.3,
"max_completion_tokens": 2048,
"stream": false
}| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | ID of the model to use. Only google/gemma-4-31b-it is available. |
messages | array | Yes | List of messages in the conversation. Message content can be plain text or multimodal content blocks. |
temperature | number | No | Sampling temperature. Use 0.7 for thinking mode, 0.3-0.5 for fast responses. |
reasoning_effort | string | No | A supported value other than "none" (for example, "low", "medium", or "high") automatically enables thinking. "none" disables thinking unless explicitly overridden by chat_template_kwargs.enable_thinking. |
chat_template_kwargs | object | No | Additional chat template options. An explicit enable_thinking value overrides the thinking behavior selected by reasoning_effort. |
mm_processor_kwargs | object | No | Image processing options. Set max_soft_tokens to control image token budget (values: 70, 140, 280, 560, 1120; default: 280). |
tools | array | No | Tool definitions for function calling. |
tool_choice | string or object | No | Controls whether and how the model selects a tool. |
max_completion_tokens | integer | No | Maximum number of tokens to generate. |
stream | boolean | No | If true, the response is streamed in chunks. Default: false. |
Response (When stream is false) ​
json
{
"id": "chat-abcdefg1234567",
"object": "chat.completion",
"created": 1770000000,
"model": "google/gemma-4-31b-it",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Retrieval augments a model with external knowledge at runtime, while fine-tuning changes model behavior through additional training."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 26,
"completion_tokens": 58,
"total_tokens": 84
}
}Response with Thinking Enabled ​
json
{
"id": "chat-abcdefg1234567",
"object": "chat.completion",
"created": 1770000000,
"model": "google/gemma-4-31b-it",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Retrieval augments a model with external knowledge at runtime, while fine-tuning changes model behavior through additional training.",
"reasoning": "Let me analyze the key differences between these two approaches. Retrieval-based methods access external data during inference, while fine-tuning modifies the model weights through training on specific data. The main distinction is when the knowledge is incorporated..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 26,
"completion_tokens": 158,
"total_tokens": 184,
"completion_tokens_details": {
"reasoning_tokens": 100
}
}
}2. List Models ​
GET /v1/models
Description ​
Lists all available models and their metadata.
Response ​
json
{
"object": "list",
"data": [
{
"id": "google/gemma-4-31b-it",
"object": "model",
"created": 1770000000,
"owned_by": "SwissAI"
}
]
}Example Code Snippets ​
Note:
The production URL for this API is available in the corresponding plan for this model in the Digital Marketplace. To retrieve the URL:
- Navigate to the Digital Marketplace.
- Go to the Documentation section.
- Select the plan associated with the
Gemma 4 31Bmodel.- Locate the production URL provided in the plan details.
- Set up the environment variable
API_URLto the production URL retrieved.
1. Text completion with curl ​
bash
curl -X POST $API_URL/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemma-4-31b-it",
"messages": [
{
"role": "user",
"content": "Compare vector search and SQL search in three short bullet points."
}
],
"temperature": 0.3,
"max_completion_tokens": 1024
}'2. Image input with Python ​
python
import base64
import os
import openai
def image_to_base64(image_path: str) -> str:
with open(image_path, "rb") as img:
return base64.b64encode(img.read()).decode("utf-8")
client = openai.OpenAI(
api_key=os.getenv("YOUR_API_KEY"),
base_url=os.getenv("API_URL") + "/v1",
)
base64_image = image_to_base64("your_image.jpg")
response = client.chat.completions.create(
model="google/gemma-4-31b-it",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Extract the key information from this screenshot."
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{base64_image}"
}
}
]
}
],
temperature=0.3,
max_completion_tokens=2048,
)
print(response.choices[0].message.content)3. Tool calling with Python ​
python
import json
import os
import openai
client = openai.OpenAI(
api_key=os.getenv("YOUR_API_KEY"),
base_url=os.getenv("API_URL") + "/v1",
)
def get_weather(location: str) -> str:
return f"The current weather in {location} is 12°C and cloudy."
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Return the current weather for a location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country"
}
},
"required": ["location"]
}
}
}
]
messages = [
{
"role": "system",
"content": "Use available tools when external information is required."
},
{
"role": "user",
"content": "What is the weather in Bern today?"
}
]
response = client.chat.completions.create(
model="google/gemma-4-31b-it",
messages=messages,
tools=tools,
tool_choice="auto",
temperature=0.3,
)
tool_calls = response.choices[0].message.tool_calls
messages.append({"role": "assistant", "tool_calls": tool_calls})
for tool_call in tool_calls:
if tool_call.function.name == "get_weather":
arguments = json.loads(tool_call.function.arguments)
result = get_weather(arguments["location"])
messages.append(
{
"role": "tool",
"tool_call_id": tool_call.id,
"name": tool_call.function.name,
"content": result,
}
)
final_response = client.chat.completions.create(
model="google/gemma-4-31b-it",
messages=messages,
temperature=0.3,
)
print(final_response.choices[0].message.content)4. Thinking mode with Python ​
python
import os
import openai
client = openai.OpenAI(
api_key=os.getenv("YOUR_API_KEY"),
base_url=os.getenv("API_URL") + "/v1",
)
response = client.chat.completions.create(
model="google/gemma-4-31b-it",
messages=[
{
"role": "user",
"content": "Explain the trade-offs between microservices and monolithic architecture for a startup building a new product."
}
],
temperature=0.7,
max_completion_tokens=2048,
reasoning_effort="high",
)
message = response.choices[0].message
print("Reasoning:", message.reasoning)
print("Answer:", message.content)5. Multimodal with thinking mode ​
python
import base64
import os
import openai
def image_to_base64(image_path: str) -> str:
with open(image_path, "rb") as img:
return base64.b64encode(img.read()).decode("utf-8")
client = openai.OpenAI(
api_key=os.getenv("YOUR_API_KEY"),
base_url=os.getenv("API_URL") + "/v1",
)
base64_image = image_to_base64("chart.png")
messages = [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Analyze this chart and explain the key trends and insights."
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{base64_image}"
}
}
],
},
]
response = client.chat.completions.create(
model="google/gemma-4-31b-it",
messages=messages,
temperature=0.7,
max_completion_tokens=4096,
reasoning_effort="high",
)
message = response.choices[0].message
print("Reasoning:", message.reasoning)
print("Answer:", message.content)6. Image token budget configuration ​
python
import base64
import os
import openai
def image_to_base64(image_path: str) -> str:
with open(image_path, "rb") as img:
return base64.b64encode(img.read()).decode("utf-8")
client = openai.OpenAI(
api_key=os.getenv("YOUR_API_KEY"),
base_url=os.getenv("API_URL") + "/v1",
)
# High token budget for OCR or detailed image analysis
base64_document = image_to_base64("document.png")
response = client.chat.completions.create(
model="google/gemma-4-31b-it",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Extract all text from this document."
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{base64_document}"
}
}
]
}
],
temperature=0.3,
max_completion_tokens=2048,
mm_processor_kwargs={
"max_soft_tokens": 1120 # High budget for OCR tasks
},
)
print(response.choices[0].message.content)
# Low token budget for simple image tasks
base64_image = image_to_base64("simple-image.jpg")
response = client.chat.completions.create(
model="google/gemma-4-31b-it",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is the main object in this image?"
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{base64_image}"
}
}
]
}
],
temperature=0.3,
max_completion_tokens=1024,
mm_processor_kwargs={
"max_soft_tokens": 70 # Low budget for simple tasks
},
)
print(response.choices[0].message.content)Replace YOUR_API_KEY with the actual API key. The authentication flow is described in Inference Endpoints Overview.
Limitations ​
- Maximum 128 tools per request
- Maximum 4 stop sequences

