Class LlmMockBuilder

java.lang.Object
org.mockserver.client.LlmMockBuilder

public class LlmMockBuilder extends Object
Fluent builder for creating LLM mock expectations.

Usage:

 llmMock("/v1/messages")
     .withProvider(Provider.ANTHROPIC)
     .withModel("claude-sonnet-4")
     .respondingWith(
         completion()
             .withText("The capital of France is Paris.")
             .withStopReason("end_turn")
             .withUsage(usage().withInputTokens(42).withOutputTokens(8))
     )
     .applyTo(mockServerClient);
 
  • Method Details

    • llmMock

      public static LlmMockBuilder llmMock(String path)
      Entry point for building an LLM mock expectation.
      Parameters:
      path - the HTTP path to match (e.g. "/v1/messages", "/v1/chat/completions")
      Returns:
      a new LlmMockBuilder
    • withProvider

      public LlmMockBuilder withProvider(Provider provider)
    • withModel

      public LlmMockBuilder withModel(String model)
    • respondingWith

      public LlmMockBuilder respondingWith(Completion completion)
    • respondingWith

      public LlmMockBuilder respondingWith(EmbeddingResponse embedding)
    • applyTo

      public Expectation[] applyTo(MockServerClient client)
      Build the expectation and register it with the MockServerClient.
      Parameters:
      client - the MockServerClient to register with
      Returns:
      the created expectations
    • build

      public Expectation build()
      Build the expectation without registering it.
      Returns:
      the built expectation