-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateResponse.java
More file actions
56 lines (44 loc) · 2.17 KB
/
CreateResponse.java
File metadata and controls
56 lines (44 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright (c) 2026 Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl/
*/
/**
* Demonstrates creating a response with the Responses API on AgentHub.
*/
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.Response;
import com.openai.models.responses.ResponseCreateParams;
import com.oracle.genai.auth.OciAuthConfig;
import com.oracle.genai.auth.OciOkHttpClientFactory;
import okhttp3.OkHttpClient;
public class CreateResponse {
// ── Configuration ──────────────────────────────────────────────────
private static final String REGION = "us-chicago-1";
private static final String PROJECT_OCID = "<<ENTER_PROJECT_ID>>";
private static final String MODEL = "xai.grok-3";
// ────────────────────────────────────────────────────────────────────
private static final String BASE_URL =
"https://inference.generativeai." + REGION + ".oci.oraclecloud.com/openai/v1";
public static void main(String[] args) {
OciAuthConfig config = OciAuthConfig.builder()
.authType("security_token")
.profile("DEFAULT")
.build();
OkHttpClient ociHttpClient = OciOkHttpClientFactory.build(config);
// AgentHub only needs project OCID — no compartment ID required
OpenAIClient client = OpenAIOkHttpClient.builder()
.baseUrl(BASE_URL)
.okHttpClient(ociHttpClient)
.apiKey("not-used")
.addHeader("openai-project", PROJECT_OCID)
.build();
Response response = client.responses().create(
ResponseCreateParams.builder()
.model(MODEL)
.input("What is 2x2?")
.build());
System.out.println(response.outputText());
}
}