Result Types
Abstract and concrete types for handling API call outcomes. All result types are subtypes of LLMRequestResponse.
Abstract Type
UniLM.LLMRequestResponse — Type
LLMRequestResponseAbstract supertype for all API call results. Pattern-match on subtypes to handle outcomes:
LLMSuccess— successful responseLLMFailure— HTTP-level failure (non-200 status)LLMCallError— exception during the call (network error, etc.)ResponseSuccess— successful Responses API resultResponseFailure— Responses API HTTP failureResponseCallError— Responses API exception
Chat Completions Results
UniLM.LLMSuccess — Type
LLMSuccess(; message, self, usage=nothing)Successful Chat Completions API response.
Fields
message::Message: The assistant's reply message.self::Chat: The updatedChatobject (with the new message appended ifhistory=true).usage::Union{TokenUsage, Nothing}: Token usage statistics from the API.
UniLM.LLMFailure — Type
LLMFailure(; response, status, self)HTTP-level failure from the Chat Completions API. The server returned a non-200 status.
Fields
response::String: The raw response body.status::Int: The HTTP status code.self::Chat: TheChatobject (unchanged).
UniLM.LLMCallError — Type
LLMCallError(; error, status=nothing, self)Exception-level error during a Chat Completions API call (network failure, JSON parse error, etc.).
Fields
error::String: The stringified exception.status::Union{Int,Nothing}: HTTP status if available.self::Chat: TheChatobject (unchanged).
Pattern Matching
result = chatrequest!(chat)
if result isa LLMSuccess
println(result.message.content)
println(result.message.finish_reason) # "stop"
elseif result isa LLMFailure
@warn "HTTP $(result.status): $(result.response)"
elseif result isa LLMCallError
@error "Call error: $(result.error)"
endResponses API Results
See also the Responses API reference.
Pattern Matching
result = respond("Tell me a joke")
if result isa ResponseSuccess
println(output_text(result))
println(result.response.status) # "completed"
elseif result isa ResponseFailure
@warn "HTTP $(result.status)"
elseif result isa ResponseCallError
@error result.error
endImage Generation Results
See also the Images API reference.
Pattern Matching
result = generate_image("A robot writing Julia code")
if result isa ImageSuccess
save_image(image_data(result)[1], "robot.png")
elseif result isa ImageFailure
@warn "HTTP $(result.status): $(result.response)"
elseif result isa ImageCallError
@error result.error
endType Hierarchy
All result types share the abstract parent LLMRequestResponse:
LLMRequestResponse
├── LLMSuccess (Chat Completions)
├── LLMFailure (Chat Completions)
├── LLMCallError (Chat Completions)
├── ResponseSuccess (Responses API)
├── ResponseFailure (Responses API)
├── ResponseCallError (Responses API)
├── ImageSuccess (Image Generation)
├── ImageFailure (Image Generation)
├── ImageCallError (Image Generation)
├── FIMSuccess (FIM Completion)
├── FIMFailure (FIM Completion)
└── FIMCallError (FIM Completion)