Gemini 3.1 Flash Lite
Text Generation • Google • ProxiedGoogle's lightest and most cost-efficient Gemini model for high-throughput tasks.
| Model Info | |
|---|---|
| Context Window ↗ | 1,000,000 tokens |
| Terms and License | link ↗ |
| More information | link ↗ |
Usage
const response = await env.AI.run( 'google/gemini-3.1-flash-lite', { contents: [ { role: 'user', parts: [ { text: 'What are the three laws of thermodynamics?', }, ], }, ], }, { gateway: { id: 'default' }, })console.log(response)Examples
With System Instruction — Using a system instruction to set context
const response = await env.AI.run( 'google/gemini-3.1-flash-lite', { systemInstruction: { parts: [ { text: 'You are a helpful coding assistant specializing in Python.', }, ], }, contents: [ { role: 'user', parts: [ { text: 'How do I read a JSON file in Python?', }, ], }, ], generationConfig: { temperature: 0.3, }, }, { gateway: { id: 'default' }, })console.log(response)Multi-turn Conversation — Continuing a conversation with context
const response = await env.AI.run( 'google/gemini-3.1-flash-lite', { contents: [ { role: 'user', parts: [ { text: 'I need help planning a road trip from San Francisco to Los Angeles.', }, ], }, { role: 'model', parts: [ { text: "I'd be happy to help! The drive is about 380 miles and takes roughly 5-6 hours. Would you like suggestions for scenic routes or interesting stops along the way?", }, ], }, { role: 'user', parts: [ { text: 'Yes, what are some good places to stop?', }, ], }, ], }, { gateway: { id: 'default' }, })console.log(response)Creative Writing — Higher temperature for creative output
const response = await env.AI.run( 'google/gemini-3.1-flash-lite', { contents: [ { role: 'user', parts: [ { text: 'Write a short story opening about a detective finding an unusual clue.', }, ], }, ], generationConfig: { temperature: 0.8, maxOutputTokens: 300, }, }, { gateway: { id: 'default' }, })console.log(response)Parameters
arrayrequiredobjectobjectarrayarrayarrayobjectstringAPI Schemas
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "contents": { "type": "array", "items": { "type": "object", "properties": { "role": { "type": "string", "enum": [ "user", "model" ] }, "parts": { "type": "array", "items": { "type": "object", "properties": { "text": { "type": "string" } }, "additionalProperties": {} } } }, "required": [ "parts" ], "additionalProperties": {} } }, "systemInstruction": { "type": "object", "properties": { "parts": { "type": "array", "items": { "type": "object", "properties": { "text": { "type": "string" } }, "additionalProperties": {} } } }, "required": [ "parts" ], "additionalProperties": {} }, "generationConfig": { "type": "object", "properties": { "temperature": { "type": "number" }, "topP": { "type": "number" }, "topK": { "type": "number" }, "maxOutputTokens": { "type": "number" }, "candidateCount": { "type": "number" }, "stopSequences": { "type": "array", "items": { "type": "string" } }, "responseMimeType": { "type": "string" } }, "additionalProperties": {} }, "safetySettings": { "type": "array", "items": { "type": "object", "properties": { "category": { "type": "string" }, "threshold": { "type": "string" } }, "required": [ "category", "threshold" ], "additionalProperties": {} } }, "tools": { "type": "array", "items": {} }, "toolConfig": {} }, "required": [ "contents" ], "additionalProperties": {}}{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "candidates": { "type": "array", "items": { "type": "object", "properties": { "content": { "type": "object", "properties": { "role": { "type": "string" }, "parts": { "type": "array", "items": { "type": "object", "properties": { "text": { "type": "string" } }, "additionalProperties": {} } } }, "required": [ "parts" ], "additionalProperties": {} }, "finishReason": { "type": "string" }, "safetyRatings": { "type": "array", "items": { "type": "object", "properties": { "category": { "type": "string" }, "probability": { "type": "string" } }, "required": [ "category", "probability" ], "additionalProperties": {} } } }, "required": [ "content" ], "additionalProperties": {} } }, "usageMetadata": { "type": "object", "properties": { "promptTokenCount": { "type": "number" }, "candidatesTokenCount": { "type": "number" }, "totalTokenCount": { "type": "number" } }, "additionalProperties": {} }, "modelVersion": { "type": "string" } }, "additionalProperties": {}}