curl -X POST https://generativelanguage.googleapis.com/v1beta/interactions \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-flash-latest",
"input": [
{ "type": "user_input", "content": [{ "type": "text", "text": "Hello!" }] },
{ "type": "model_output", "content": [{ "type": "text", "text": "Hi there! How can I help you today?" }] },
{ "type": "user_input", "content": [{ "type": "text", "text": "What is the capital of France?" }] }
]
}'
from google import genai
client = genai.Client()
response = client.interactions.create(
model="gemini-flash-latest",
input=[
{
"type": "user_input",
"content": [{"type": "text", "text": "Hello!"}],
},
{
"type": "model_output",
"content": [{
"type": "text",
"text": "Hi there! How can I help you today?",
}],
},
{
"type": "user_input",
"content": [
{"type": "text", "text": "What is the capital of France?"}
],
},
],
)
print(response.output_text)
import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({});
const interaction = await ai.interactions.create({
model: 'gemini-flash-latest',
input: [
{type: 'user_input', content: [{type: 'text', text: 'Hello'}]},
{
type: 'model_output',
content: [
{type: 'text', text: 'Hi there! How can I help you today?'},
],
},
{
type: 'user_input',
content: [{type: 'text', text: 'What is the capital of France?'}],
},
],
});
console.log(interaction.output_text);
import com.google.genai.Client;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import com.google.genai.gaos.models.operations.CreateInteractionResponse;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.ModelOutputStep;
import com.google.genai.gaos.models.interactions.Step;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.interactions.UserInputStep;
Client client = new Client();
List conversation =
List.of(
UserInputStep.builder()
.content(List.of(TextContent.builder().text("Hello!").build()))
.build(),
ModelOutputStep.builder()
.content(
List.of(
TextContent.builder().text("Hi there! How can I help you today?").build()))
.build(),
UserInputStep.builder()
.content(
List.of(TextContent.builder().text("What is the capital of France?").build()))
.build());
CreateModelInteraction params =
CreateModelInteraction.builder()
.model("gemini-flash-latest")
.input(InteractionsInput.ofStep(conversation))
.build();
CreateInteractionResponse response =
client.interactions.create(CreateInteractionRequestBody.of(params));
Interaction interaction =
response.interaction().orElseThrow(() -> new RuntimeException("No interaction returned"));
System.out.println(interaction.outputText().orElse(""));
package main
import (
"context"
"fmt"
"log"
"google.golang.org/genai"
gaos_interactions "google.golang.org/genai/interactions/models/interactions"
"google.golang.org/genai/interactions/models/operations"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
history := []gaos_interactions.Step{
gaos_interactions.NewStep(gaos_interactions.UserInputStep{
Content: []gaos_interactions.Content{
gaos_interactions.NewContent(gaos_interactions.TextContent{
Text: "Hello!",
}),
},
}),
gaos_interactions.NewStep(gaos_interactions.ModelOutputStep{
Content: []gaos_interactions.Content{
gaos_interactions.NewContent(gaos_interactions.TextContent{
Text: "Hi there! How can I help you today?",
}),
},
}),
gaos_interactions.NewStep(gaos_interactions.UserInputStep{
Content: []gaos_interactions.Content{
gaos_interactions.NewContent(gaos_interactions.TextContent{
Text: "What is the capital of France?",
}),
},
}),
}
body := operations.NewCreateInteractionRequestBody(gaos_interactions.CreateModelInteraction{
Model: gaos_interactions.Model("gemini-flash-latest"),
Input: genai.Ptr(gaos_interactions.NewInteractionsInput(history)),
})
res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{Body: body})
if err != nil {
log.Fatal(err)
}
if res.Interaction != nil && res.Interaction.OutputText != nil {
fmt.Println(*res.Interaction.OutputText)
}
}