Skip to content

Commit 1ecc8e1

Browse files
committed
Add example token_auth.java
1 parent a720399 commit 1ecc8e1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

examples/token_auth.java

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
3+
//JAVA 17+
4+
//REPOS mavencentral,jitpack=https://jitpack.io
5+
//DEPS com.github.tadayosi:torchserve-client-java:main-SNAPSHOT
6+
7+
import com.github.tadayosi.torchserve.client.TorchServeClient;
8+
import com.github.tadayosi.torchserve.client.model.ApiException;
9+
10+
public class token_auth {
11+
12+
/**
13+
* You can find the auth token for the inference API by looking at the
14+
* `key_file.json` in the current directory of the TorchServe server.
15+
*/
16+
private static String INFERENCE_AUTH_TOKEN = "<inference-key>";
17+
18+
public static void main(String... args) throws Exception {
19+
try {
20+
var client = TorchServeClient.builder()
21+
.inferenceKey(INFERENCE_AUTH_TOKEN)
22+
.build();
23+
var response = client.inference().ping();
24+
System.out.println(response);
25+
} catch (ApiException e) {
26+
e.printStackTrace();
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)