Evaliphy is currently in beta. It is not recommended for production use yet. Please try it out and share your feedback.

HTTP Client

Evaliphy provides a built-in HTTP client fixture to simplify calling your RAG application's API. It's a higher-level interface over the native Fetch API, automatically handling retries, timeouts, and session management.

Usage in Evaluations

The httpClient is provided as a fixture in the evaluate function.

import { evaluate } from 'evaliphy';

evaluate('My RAG Test', async ({ httpClient }) => {
  const response = await httpClient.post('/chat', {
    query: "What is Evaliphy?"
  });

  const data = await response.json();
  // ... assertions
});

Non-Streaming Requests

For standard JSON APIs, use the standard HTTP methods. These return an EvalResponse object.

Methods

  • httpClient.get(url, options?)
  • httpClient.post(url, payload, options?)
  • httpClient.put(url, payload, options?)
  • httpClient.patch(url, payload, options?)
  • httpClient.delete(url, options?)

Handling the Response

The EvalResponse object provides easy access to the response data and metadata:

const res = await httpClient.post('/chat', payload);

await res.json();       // Parsed JSON body
await res.text();       // Raw text body
res.status;             // HTTP status code
res.headers;            // Response headers
res.timings.ttfb;       // Time to first byte (ms)
res.timings.total;      // Total request duration (ms)

Streaming Requests (Unstable)

⚠️ Warning: Streaming support is currently unstable and may undergo significant changes in future beta releases.

For LLM completions or Server-Sent Events (SSE), use the stream method. It returns a StreamResponse which is an async iterable.

const stream = await httpClient.stream('/chat', { query: "..." });

for await (const chunk of stream) {
  console.log(chunk.text); // Access the text content of the chunk
}

// You can also collect the entire stream into a single string
const fullText = await stream.collect();

The StreamResponse also includes timing information:

  • stream.timings.ttfb: Time to first byte.
  • stream.timings.streamEnd: Time until the last chunk was received.

Session Management

Use withSession to create a scoped client that automatically includes a session identifier in every request. This is essential for testing multi-turn conversations.

const session = httpClient.withSession('abc-123');

await session.post('/chat', { message: "First turn" });
await session.post('/chat', { message: "Second turn" }); // Still uses 'abc-123'

Request Options

Every request method accepts an optional RequestOptions object to override global settings:

await httpClient.post('/chat', payload, {
  timeout: 10000,
  headers: { 'X-Custom-Header': 'value' },
  retry: { attempts: 3, delay: 500 }
});