All API endpoints, including this one, require an x-api-key header for authentication. Refer to the Authentication section for more details.

Endpoint

POST /experiment/:slug/log

Path Parameters

NameTypeDescription
slugstringRequired. The unique slug of the experiment.

Request Body

The request body must be a JSON object containing details about the variant execution.
{
  "variantKey": "A",
  "input": {
    "query": "What are the latest AI advancements?"
  },
  "output": {
    "response": "Recent AI advancements include improvements in large language models and generative AI."
  },
  "metrics": {
    "latency_ms": 123,
    "token_count": 78,
    "user_rating": 5
  },
  "context": {
    "session_id": "session_abc_123",
    "environment": "production"
  }
}
Fields:
  • variantKey (string, required): The key of the variant that was executed (e.g., “A”, “B”). This should match a variant defined in the experiment.
  • input (object, optional): The input provided to the AI agent or prompt workflow for this execution.
  • output (object, optional): The output received from the AI agent or prompt workflow.
  • metrics (object, optional): Any quantitative metrics recorded for this execution (e.g., latency, token count, cost).
  • context (object, optional): An optional JSON object that can contain any contextual information relevant to this log entry (e.g., session information, environment).

Response Body

On successful logging, the server responds with a simple success message. Success (200 OK):
{
  "success": true,
  "logId": "log_xxxxxxxxxxxx"
}
Fields:
  • success (boolean): Indicates whether the log entry was successfully recorded.
  • logId (string): A unique identifier for the created log entry.
Error Responses:
  • 400 Bad Request: If the request body is malformed or variantKey is missing.
  • 401 Unauthorized: If the x-api-key is missing or invalid.
  • 404 Not Found: If no experiment with the given slug is found.
  • 500 Internal Server Error: If there was an unexpected error during the logging process.