Skip to main content
Version: 4.7.66

Experiments

🛑Alpha

OpenTelemetry support is currently in alpha and may undergo significant changes.

Experiments

The experiments SDK provides programmatic access to Gentrace experiments. While typically created via the experiment() function, experiments can also be accessed and managed directly through the SDK.

Overview​

The SDK is built by Stainless and provides type-safe access to Gentrace entities. The experiments object exposes methods to create, retrieve, update, and list experiments.

Basic usage​

typescript
import { init, experiments } from 'gentrace';
init({
apiKey: process.env.GENTRACE_API_KEY,
});
// List experiments
const experimentList = await experiments.list();
// Access the experiments
for (const experiment of experimentList.data) {
console.log(experiment.name);
console.log(experiment.metadata);
}

Experiment structure​

Each experiment contains:

  • id: Unique identifier (UUID)
  • name: Optional friendly name for the experiment
  • pipelineId: UUID of the associated pipeline
  • metadata: Optional metadata object for custom data
  • createdAt: Creation timestamp
  • updatedAt: Last update timestamp

Resource methods​

Create an experiment​

typescript
const experiment = await experiments.create({
pipelineId: 'pipeline-uuid',
name: 'Prompt optimization experiment',
metadata: {
temperature: 0.7,
model: 'gpt-4o',
}
});

Retrieve an experiment​

typescript
const experiment = await experiments.retrieve('experiment-id');
console.log(experiment.pipelineId);

Update an experiment​

typescript
const experiment = await experiments.update('experiment-id', {
name: 'Updated experiment name',
metadata: { version: 2 },
status: 'EVALUATING',
});

List with filters​

typescript
// Filter by pipeline
const experimentList = await experiments.list({
pipelineId: 'pipeline-id',
});

Common usage with experiment()​

Experiments are typically created automatically when using the experiment() function:

typescript
import { experiment } from 'gentrace';
// This automatically creates an experiment
experiment(PIPELINE_ID, async () => {
// Your evaluation code here
});

See also​