Skip to content

streamResponse delivers only a single final snapshot — no partial content #2

@artemnovichkov

Description

@artemnovichkov

Description

session.streamResponse(to:generating:) with ClaudeLanguageModel never yields partial snapshots. The for try await loop receives exactly one element containing the complete response, after the full generation time. Same behavior on the Simulator and on a physical device. With SystemLanguageModel, the same code streams partials as expected.

Environment

  • ClaudeForFoundationModels 0.1.1
  • Xcode 27 beta, iOS 27 beta (Simulator and device)
  • Model: .sonnet4_6, auth: .apiKey

Minimal reproduction

import FoundationModels
import ClaudeForFoundationModels

@Generable
struct Ideas: Equatable {
    @Guide(description: "Gift ideas", .count(5))
    var ideas: [String]
}

let model = ClaudeLanguageModel(
    name: .sonnet4_6,
    auth: .apiKey("YOUR_API_KEY")
)
let session = LanguageModelSession(model: model)

var snapshots = 0
let stream = session.streamResponse(
    to: "Suggest gift ideas for a sci-fi fan.",
    generating: Ideas.self
)
for try await partial in stream {
    snapshots += 1
    print("snapshot \(snapshots):", partial.content)
}
print("total snapshots:", snapshots) // 1 — arrives only when generation completes

Expected

Multiple cumulative PartiallyGenerated snapshots as content streams in (as with SystemLanguageModel).

Actual

A single snapshot with the complete result, delivered at the end.

Notes

I'm not sure the issue related to the framework or to Foundation Models, but maybe you know the solution to fix it. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions