Skip to content

Commit e731703

Browse files
chengzeyiclaude
andcommitted
Results carry the API's optional details object; the example no longer casts outputs to strings
run() adds `details` (structured information about the outputs) when the model returns it, and RunNoThrowResult has getDetails(). The package example iterates the outputs as objects: a model may return text or a structured result, not only URL strings. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 998be68 commit e731703

3 files changed

Lines changed: 82 additions & 4 deletions

File tree

‎src/main/java/ai/wavespeed/api/Client.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ private Map<String, Object> wait(
502502
if ("completed".equals(status)) {
503503
Map<String, Object> output = new HashMap<>();
504504
output.put("outputs", data.get("outputs"));
505+
if (data.get("details") != null) {
506+
output.put("details", data.get("details"));
507+
}
505508
return output;
506509
}
507510

@@ -642,6 +645,9 @@ public Map<String, Object> run(
642645

643646
Map<String, Object> output = new HashMap<>();
644647
output.put("outputs", data.get("outputs"));
648+
if (data.get("details") != null) {
649+
output.put("details", data.get("details"));
650+
}
645651
return output;
646652
}
647653

@@ -877,14 +883,22 @@ public RunDetail(String taskId, String status, String model, String error, Strin
877883
*/
878884
public static class RunNoThrowResult {
879885
private final Object outputs;
886+
private final Object details;
880887
private final RunDetail detail;
881888

882889
public RunNoThrowResult(Object outputs, RunDetail detail) {
890+
this(outputs, null, detail);
891+
}
892+
893+
public RunNoThrowResult(Object outputs, Object details, RunDetail detail) {
883894
this.outputs = outputs;
895+
this.details = details;
884896
this.detail = detail;
885897
}
886898

887899
public Object getOutputs() { return outputs; }
900+
/** Structured information about the outputs (the API's "details" object); null when absent. */
901+
public Object getDetails() { return details; }
888902
public RunDetail getDetail() { return detail; }
889903
}
890904

@@ -963,6 +977,7 @@ public RunNoThrowResult runNoThrow(
963977
String createdAt = (String) data.get("created_at");
964978
return new RunNoThrowResult(
965979
data.get("outputs"),
980+
data.get("details"),
966981
new RunDetail(taskId, "completed", model, null, createdAt)
967982
);
968983
}
@@ -972,6 +987,7 @@ public RunNoThrowResult runNoThrow(
972987
Map<String, Object> result = wait(submitResult.requestId, timeout, poll);
973988
return new RunNoThrowResult(
974989
result.get("outputs"),
990+
result.get("details"),
975991
new RunDetail(submitResult.requestId, "completed", model, null, null)
976992
);
977993
} catch (Exception waitError) {

‎src/main/java/ai/wavespeed/api/package-info.java‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@
1212
* Map.of("prompt", "A beautiful sunset over mountains")
1313
* );
1414
*
15-
* // Get first output URL
16-
* @SuppressWarnings("unchecked")
17-
* List<String> outputs = (List<String>) output.get("outputs");
18-
* System.out.println(outputs.get(0));
15+
* // Each output is a String (a file URL, or plain text) or a Map (structured result)
16+
* List<?> outputs = (List<?>) output.get("outputs");
17+
* for (Object item : outputs) {
18+
* if (item instanceof String) {
19+
* System.out.println(item);
20+
* } else {
21+
* System.out.println("Structured output: " + item);
22+
* }
23+
* }
24+
*
25+
* // Optional structured information about the outputs (absent for most models)
26+
* Object details = output.get("details");
1927
*
2028
* // Upload a file
2129
* String url = Wavespeed.upload("/path/to/image.png");

‎src/test/java/ai/wavespeed/ClientTest.java‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,60 @@ void testSubmitFailure() {
109109
});
110110
}
111111

112+
@Test
113+
void testRunCarriesObjectOutputsAndDetails() throws IOException {
114+
String responseJson = "{\"data\": {\"status\": \"completed\", " +
115+
"\"id\": \"req-123\", " +
116+
"\"outputs\": [{\"url\": \"https://example.com/a.mp4\", \"duration\": 5}], " +
117+
"\"details\": {\"clips\": [{\"start\": 0, \"end\": 5}]}}}";
118+
Client client = createClientWithMockHttp("test-key", createMockHttpClient(200, responseJson));
119+
120+
Map<String, Object> output = client.run(
121+
"wavespeed-ai/z-image/turbo",
122+
Map.of("prompt", "test"),
123+
null, null, true, null // enableSyncMode = true
124+
);
125+
126+
List<?> outputs = (List<?>) output.get("outputs");
127+
assertEquals("https://example.com/a.mp4", ((Map<?, ?>) outputs.get(0)).get("url"));
128+
assertTrue(((Map<?, ?>) outputs.get(0)).containsKey("duration"));
129+
assertTrue(((Map<?, ?>) output.get("details")).containsKey("clips"));
130+
}
131+
132+
@Test
133+
void testRunNoThrowCarriesDetails() throws IOException {
134+
String responseJson = "{\"data\": {\"status\": \"completed\", " +
135+
"\"id\": \"req-123\", " +
136+
"\"outputs\": [\"https://example.com/a.mp4\"], " +
137+
"\"details\": {\"clips\": [{\"start\": 0, \"end\": 5}]}}}";
138+
Client client = createClientWithMockHttp("test-key", createMockHttpClient(200, responseJson));
139+
140+
Client.RunNoThrowResult result = client.runNoThrow(
141+
"wavespeed-ai/z-image/turbo",
142+
Map.of("prompt", "test"),
143+
null, null, true, null
144+
);
145+
146+
assertEquals(List.of("https://example.com/a.mp4"), result.getOutputs());
147+
assertTrue(((Map<?, ?>) result.getDetails()).containsKey("clips"));
148+
}
149+
150+
@Test
151+
void testRunHasNoDetailsKeyWhenAbsent() throws IOException {
152+
String responseJson = "{\"data\": {\"status\": \"completed\", " +
153+
"\"id\": \"req-123\", " +
154+
"\"outputs\": [\"https://example.com/out.png\"]}}";
155+
Client client = createClientWithMockHttp("test-key", createMockHttpClient(200, responseJson));
156+
157+
Map<String, Object> output = client.run(
158+
"wavespeed-ai/z-image/turbo",
159+
Map.of("prompt", "test"),
160+
null, null, true, null // enableSyncMode = true
161+
);
162+
163+
assertFalse(output.containsKey("details"));
164+
}
165+
112166
@Test
113167
void testGetResultSuccess() {
114168
// Test successful result retrieval

0 commit comments

Comments
 (0)