Guide · LLM APIs
AvailableTest AI clients without calling a live provider
Point an OpenAI-compatible or provider-shaped client at DotMock and return deterministic content, tool calls, structured output, failures, and streams. Your application keeps using its real SDK and parsing path.
In this guide
- Run an existing AI client against a mock base URL
- Model content, tools, JSON, and provider errors
- Make multi-turn tests deterministic
- Inspect prompts, matches, frames, and responses
Prerequisites
- A DotMock workspace you can access
- The API ID in $API_ID and its published runtime URL in $MOCK_URL when the example calls the mock
On this page
Create an LLM workspace
Choose LLM API when creating the workspace. The workspace exposes provider-shaped HTTP routes and keeps fixtures, tester conversations, traffic, state, and settings together.
- OpenAI chat completions and Responses API
- Anthropic message-shaped requests and responses
- Gemini and Ollama provider-shaped traffic inspection
- HTTP/SSE and WebSocket fixture protocols
Change the base URL, not the client behavior
Keep the SDK, request body, tool definitions, response parser, and retry logic your application already uses. Replace only the provider base URL and use a non-secret test key if the SDK requires one.
const client = new OpenAI({
apiKey: "test-key",
baseURL: process.env.DOTMOCK_LLM_URL,
});
const response = await client.responses.create({
model: "gpt-4.1-mini",
input: "Summarize order ord_123",
});Fixtures define the behavior
A fixture combines ordered match triggers with a response or workflow. Match normalized request data such as provider, endpoint, model, user message, system prompt, tool name, tool result, or custom field conditions.
on: model = gpt-4.1-mini AND user message contains "order"
run: call get_order({"id":"ord_123"})
response: "Order ord_123 is ready to ship."Return the outcome your app must handle
Use direct assistant content for ordinary cases, tool calls for agent loops, structured JSON for schema-bound clients, workflow responses after tool results, and provider-shaped errors for retry and fallback code.
- Content with finish reason and token usage
- One or more tool calls with typed JSON arguments
- Structured JSON content
- HTTP error status, message, and provider error type
- State-backed sequences and per-user counters
Test with the built-in conversation panel
Choose Chat Completions or Responses API, HTTP/SSE or WebSocket, model, system prompt, and streaming mode. The result shows the matched fixture, assistant content, tool calls, and raw frames. Inspect traffic for the complete normalized request and response.