BoundaryML/baml · error

failed to get http request: %w

Error message

failed to get http request: %w

What it means

LLMCall.HttpRequest() wraps any error from CallMethod(l, "http_request", nil) when fetching the HTTP request object associated with the LLM call. It means the runtime failed to resolve the "http_request" attribute — usually a stale/freed object handle or an FFI dispatch failure. Without this the caller cannot inspect the outbound LLM API request.

Source

Thrown at engine/language_client_go/pkg/rawobjects_llm_call.go:67

func (l *llmCall) Provider() (string, error) {
	result, err := raw_objects.CallMethod(l, "provider", nil)
	if err != nil {
		return "", fmt.Errorf("failed to get provider: %w", err)
	}

	provider, ok := result.(string)
	if !ok {
		return "", fmt.Errorf("unexpected type for provider: %T", result)
	}

	return provider, nil
}

func (l *llmCall) HttpRequest() (HTTPRequest, error) {
	result, err := raw_objects.CallMethod(l, "http_request", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get http request: %w", err)
	}

	request, ok := result.(HTTPRequest)
	if !ok {
		return nil, fmt.Errorf("unexpected type for http request: %T", result)
	}

	return request, nil
}

func (l *llmCall) HttpResponse() (HTTPResponse, error) {
	result, err := raw_objects.CallMethod(l, "http_response", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get http response: %w", err)
	}

	if result == nil {
		return nil, nil

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Inspect HttpRequest() inside the callback/scope that produced the LLMCall.
  2. Keep the runtime alive (e.g. don't stop/close the BAML runtime) until all call objects have been consumed.
  3. Match Go binding and native runtime versions, then regenerate bindings.
  4. Unwrap the error to identify the precise FFI failure before attempting alternatives.

Example fix

// before
req, err := call.HttpRequest()
// err: failed to get http request (object freed)

// after: consume in event scope
onEvent := func(ev baml.Event) {
    req, err := ev.Call().HttpRequest()
    if err != nil {
        log.Printf("request unavailable: %v", err)
        return
    }
    _ = req
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Consume the request while the runtime guarantees liveness:
func inspectRequest(ev baml.Event) {
    if ev.Call() == nil { return } // must be inside event scope
}

Try / catch

req, err := call.HttpRequest()
if err != nil {
    log.Printf("http request unavailable: %v", err)
    return
}

Prevention

When it happens

Trigger: Calling HttpRequest() on an llmCall whose backing RawObject was released by the Rust runtime, or when the "http_request" method call itself returns an error across the FFI boundary.

Common situations: Deferring HTTP request inspection until after the BAML function completed and objects were cleaned up; version mismatch between Go bindings and native runtime; concurrent access to runtime-owned handles from multiple goroutines.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/02c6860623804a34. Report an issue: GitHub.