Class BetaMessageThread

  • All Implemented Interfaces:

    
    public final class BetaMessageThread
    
                        

    A message thread (beta) keeps the conversation on the server, so each request sends only the new messages instead of the whole conversation. A thread runs one turn at a time.

    Create one with MessageService.thread, which takes what MessageService.create takes and sends nothing until the first turn. For example:

    BetaMessageThread thread = client.beta().messages().thread(
        ThreadCreateParams.builder()
            .model("claude-sonnet-5-5")
            .maxTokens(1024)
            .build());
    
    BetaMessage first = thread.send("Hello");
    BetaMessage second = thread.send("And again");

    toolRunner runs the tool loop over this thread. For replies in the JSON schema derived from a class, see StructuredBetaMessageThread.