How to get detailed error with http status code and header?

Currently when I uses aisdkv5 with mastra and do
const result = agent.stream(...)
const result = agent.stream(...)
When a error happens with the provider API, for example 503 or 429, it seems there no way for me to get the response status code or headers to understand what is going on, for example for 429 I would want to read the header to know when I can retry. I have tried to use the onError callback and reading the stream and reading result.error all of them give me a stripped error that doesn't include http status code or response. These detailed field should exist in the underlying aisdk error like AI_APICallError and it is even logged out by mastra, but it seems mastra doesn't return or throw the detailed error for consumer to use it only give consumer a stripped down version of the error? is there a way I can get the full error?
AI_APICallError
Learn how to fix AI_APICallError
3 Replies
Mastra Triager
GitHub
[DISCORD:1426478654912991262] How to get detailed error with http s...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1426478654912991262 Currently when I uses aisdkv5 with mastra and do const result = agent.stream(...) When...
LekoArts
LekoArts7d ago
Are you using the latest Mastra versions? We merged https://github.com/mastra-ai/mastra/pull/8567 in the latest release which passes errors along
GitHub
fix(deployer): Handle errors in Agent streams by LekoArts · Pull R...
Description Tip: Review the file changes with "Hide whitespace changes" In our stream handlers for agents we currently return 200 OK status even when errors occur. These errors we...
Super
SuperOP6d ago
i just tried "@mastra/core": "~0.21.0", still doesn't seem to be able to get the error I am doing smt like this:
const run = await mastra.getWorkflow('...').createRunAsync()

const workflowStream = run.stream({
inputData: { ... },
})

for await (const part of workflowStream.stream) {
logger.info(part)
}

...

const wfState = await workflowStream.getWorkflowState()
logger.info(wfState.error)
const run = await mastra.getWorkflow('...').createRunAsync()

const workflowStream = run.stream({
inputData: { ... },
})

for await (const part of workflowStream.stream) {
logger.info(part)
}

...

const wfState = await workflowStream.getWorkflowState()
logger.info(wfState.error)
In my step I am using smt like this:
const result = await someAgent.stream(input, {
format: 'aisdk',
...
}

...
const result = await someAgent.stream(input, {
format: 'aisdk',
...
}

...
I tried to read the stream of both the workflow and agent, and then I tried to read the workflow state, I wasn't able to get the full error, the error I got is a string of stacktrace, no other detail like statusCode or the response

Did you find this page helpful?