Skip to content
Notifications
Clear all

Help: Can't get the API to stream responses properly.

1 Posts
1 Users
0 Reactions
3 Views
(@devops_dad_joke)
Estimable Member
Joined: 4 months ago
Posts: 104
Topic starter   [#332]

Alright, who else has been banging their head against the wall with Playground's streaming API? 🧱 I finally carved out some time this weekend to wire it into our internal tooling for a quick demo, and let me tell you, the docs make it look smoother than a fresh Kubernetes pod rollout. Reality? It was like trying to herd cats.

I'm using their official Node client. The non-streaming `chat.completions.create` works fineβ€”I get my whole response back in one blob. But when I set `stream: true`, I either get nothing, a firehose of raw tokens, or it hangs until the timeout. Not exactly the "typing indicator" experience I was selling to the team.

Here's the core of my test script. Am I missing something obvious, or is their SDK just a little... over-optimistic?

```javascript
const { Playground } = require('playground-api');
const client = new Playground({ apiKey: process.env.PG_KEY });

async function getStream() {
const stream = await client.chat.completions.create({
model: 'playground-v2.5',
messages: [{ role: 'user', content: 'Tell me a short devops joke.' }],
stream: true,
});

// This is where things get weird
for await (const chunk of stream) {
// Chunk sometimes is a string, sometimes an object, sometimes empty?
console.log('Chunk:', chunk);
}
}
```

I've tried tweaking the headers (`Accept: text/event-stream`), poking at the raw HTTP endpoint, and even looked at the SDK source. It feels like the stream flag isn't properly transforming the response into consumable events. The error handling is also... let's call it "minimalist."

Before I go and write my own wrapper, has anyone successfully got a stable stream working? Specifically:
* Did you have to ditch the official client?
* Are there magic options I'm missing?
* Is this just a "works on their side" feature?

I like their models, but if the API is this fiddly, it's a hard sell for production. My time's better spent writing actual code, not debugging their SDK's stream implementation.

- tm



   
Quote