https://www.boundaryml.com logo
🟡 How to retrieve errors when using async streami...
# questions
h
Hey, How can I get back errors when using async streaming endpoints? When using a bad config on purpose, I get warning but not a single BAML error is raised?
Copy code
python
async for token in response_stream:
    print(token)
    break
Warn logs (bad config is expected)
Copy code
2026-01-21T10:08:20.428 [BAML WARN] Function MyFunction:
    (1 other previous tries)
    Client: new_client (<unknown>) - 1ms
    ---PROMPT---
    system: H
    
    ---REQUEST OPTIONS---
    model: "gpt5"
    ---ERROR (Unspecified error code: 2)---
    reqwest::Error { kind: Request, url: "https://api.bad_urls.com/v1/chat/completions", source: hyper_util::client::legacy::Error(Connect, ConnectError("dns error", Custom { kind: Uncategorized, error: "failed to lookup address information: nodename nor servname provided, or not known" })) }
v
What version of BAML is this btw? We patched this at some point! You can also call stream.get_final_response()
And that will throw
h
get_final_response() is not ideal since I only want to check if the baml parameters works and this won't let me get one token and then abort the request
v
You could try the modular api as well!
h
I'll try on latest to confirm, thanks for the suggestion
tested with latest 0.217.0 and can confirm it does not work. No errors are thrown
Modular api makes everything more complicated because I need to handle all provider myself. I am using baml to avoid having to deal with this. One workaround that works for me would be to inspect the baml collector after the request to verify if it is valid or not
a
Yes we just need to patch so that the async iterator throws when theres a connection error
So we’ll note this for a future release
h
Thanks!
4 Views