or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

batch-operations.mdcaching.mdchat-sessions.mdclient-configuration.mdcontent-generation.mdembeddings-tokens.mderror-handling.mdfile-search-stores.mdfiles-management.mdimage-operations.mdindex.mdlive-sessions.mdmodel-tuning.mdoperations.mdtools-functions.mdtypes-reference.mdvideo-generation.md

operations.mddocs/

0

# Operations Management

1

2

Manage long-running operations like video generation and model tuning jobs.

3

4

## Core Imports

5

6

```java

7

import com.google.genai.Operations;

8

import com.google.genai.AsyncOperations;

9

import com.google.genai.Pager;

10

import com.google.genai.types.Operation;

11

import com.google.genai.types.GenerateVideosOperation;

12

import com.google.genai.types.TuningOperation;

13

```

14

15

## Operations Service

16

17

```java { .api }

18

package com.google.genai;

19

20

public final class Operations {

21

public Operation get(String name, GetOperationConfig config);

22

public void cancel(String name, CancelOperationConfig config);

23

public DeleteResourceJob delete(String name, DeleteOperationConfig config);

24

public Pager<Operation> list(ListOperationsConfig config);

25

public Operation wait(String name, WaitOperationConfig config);

26

}

27

```

28

29

## Operation Type

30

31

```java { .api }

32

package com.google.genai.types;

33

34

public final class Operation {

35

public Optional<String> name();

36

public Optional<JsonNode> metadata();

37

public Optional<Boolean> done();

38

public Optional<Status> error();

39

public Optional<JsonNode> response();

40

}

41

```

42

43

## Get Operation

44

45

```java

46

Operation op = client.operations.get("operations/abc123", null);

47

48

System.out.println("Operation: " + op.name().orElse("N/A"));

49

System.out.println("Done: " + op.done().orElse(false));

50

51

if (op.done().orElse(false)) {

52

op.response().ifPresent(response -> {

53

System.out.println("Result: " + response);

54

});

55

} else {

56

System.out.println("Still processing...");

57

}

58

```

59

60

## Wait for Operation

61

62

```java

63

Operation op = client.operations.wait("operations/abc123", null);

64

65

if (op.error().isPresent()) {

66

System.err.println("Operation failed: " + op.error().get());

67

} else {

68

System.out.println("Operation completed successfully");

69

}

70

```

71

72

## Poll Operation

73

74

```java

75

GenerateVideosOperation videoOp = client.models.generateVideos(...);

76

77

while (!videoOp.done().isPresent()) {

78

Thread.sleep(10000);

79

videoOp = client.operations.getVideosOperation(videoOp, null);

80

System.out.println("Status: " + videoOp.name().orElse("N/A"));

81

}

82

83

videoOp.response().ifPresent(response -> {

84

response.generatedVideos().ifPresent(videos -> {

85

System.out.println("Generated " + videos.size() + " videos");

86

});

87

});

88

```

89

90

## Cancel Operation

91

92

```java

93

client.operations.cancel("operations/abc123", null);

94

System.out.println("Operation cancelled");

95

```

96

97

## Delete Operation

98

99

```java

100

DeleteResourceJob result = client.operations.delete("operations/abc123", null);

101

System.out.println("Operation deleted");

102

```

103

104

## List Operations

105

106

```java

107

Pager<Operation> pager = client.operations.list(null);

108

109

for (Operation op : pager) {

110

System.out.println("Op: " + op.name().orElse("N/A"));

111

System.out.println(" Done: " + op.done().orElse(false));

112

}

113

```

114