Result Types

Abstract and concrete types for handling API call outcomes. All result types are subtypes of LLMRequestResponse.

Abstract Type

Chat Completions Results

UniLM.LLMSuccessType
LLMSuccess(; message, self, usage=nothing)

Successful Chat Completions API response.

Fields

  • message::Message: The assistant's reply message.
  • self::Chat: The updated Chat object (with the new message appended if history=true).
  • usage::Union{TokenUsage, Nothing}: Token usage statistics from the API.
source
UniLM.LLMFailureType
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: The Chat object (unchanged).
source
UniLM.LLMCallErrorType
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: The Chat object (unchanged).
source

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)"
end

Responses 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
end

Image 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
end

Type 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)