OpenAI creates a fake OpenAI-compatible test server with a sensible default handler and returns its base URL. It handles both the Responses API (/responses) and the Chat Completions API (/chat/completions). Non-streaming requests (e.g. structured-output title generation) receive a JSON payload sati
(t testing.TB)
| 176 | // text chunk. Use NewOpenAI when a test needs control over the |
| 177 | // response. |
| 178 | func OpenAI(t testing.TB) string { |
| 179 | t.Helper() |
| 180 | return NewOpenAI(t, func(req *OpenAIRequest) OpenAIResponse { |
| 181 | if req.Stream { |
| 182 | return OpenAIStreamingResponse(OpenAITextChunks("Hello from test server.")...) |
| 183 | } |
| 184 | return OpenAINonStreamingResponse(`{"title": "Test Chat"}`) |
| 185 | }) |
| 186 | } |
| 187 | |
| 188 | // NewOpenAI creates a new OpenAI test server with a handler function. |
| 189 | // The handler is called for each request and should return either a streaming |