cloudflare / cloudflare/cloudflare-typescript

[Workers AI] Undefined result for models that return binary output

Open
#2,695 2 comments 0 reactions 0 assignees View on GitHub
kind: bug
Dominant language
TypeScript
Stars
814
Forks
190
Avg merge
1h 38m
Merged PRs (30d)
2

Description

### Confirm this is a Typescript library issue and not an underlying Cloudflare API issue

- [x] This is an issue with the Typescript library

### Describe the bug

Hello!

I can't tell if I'm holding the SDK wrong, but when I use the Typescript SDK to run a model like [`leonardo/phoenix-1.0`](https://developers.cloudflare.com/workers-ai/models/phoenix-1.0/) that, according to the docs, returns the following payload...

```json
{
"type": "string",
"contentType": "image/jpeg",
"format": "binary",
"description": "The generated image in JPEG format"
}
```

...I get an undefined output. If I run a model that returns a base64 string (like [`schnell`](https://developers.cloudflare.com/workers-ai/models/flux-1-schnell/)), I get back a JSON object that correctly reflects the type that's in the documentation.

What could I be doing wrong?

### To Reproduce

Run this snippet:

```ts
import Cloudflare from 'cloudflare';

const client = new Cloudflare({
apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const output = await client.ai.run("@cf/leonardo/phoenix-1.0", {
prompt: "A cat eating soup dumplings",
account_id: process.env['CLOUDFLARE_ACCOUNT_ID']!,
})
console.log('Output type:', typeof output);
console.log('Output:', output);
```

Observe this output:
```
Output type: undefined
Output: undefined
```

### Code snippets

```Typescript

```

### OS

macOS

### Runtime version

Typescript 5.7.3

### Library version

v5.2.0

Contributor guide

Open the contributing guide

Research direction

Start at the client.ai.run entry point shown in the reproduction and trace how responses are handled for the binary-output model versus the base64-string model. Run the provided snippet against leonardo/phoenix-1.0 and confirm that the binary result is returned instead of undefined; add coverage for this behavior if the surrounding code has tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
ai, api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.