Skip to main content

Create an API Key

  1. In your organization’s DeepRails API Console, go to API Keys.
  2. Click Create key, name it, then copy the key.
  3. (Optional) Save it as the DEEPRAILS_API_KEY environment variable.
API Keys – placeholder

Create and manage API keys in the API Console.

Install the SDK

pip install deeprails

Create a Monitor

Before you can send events, you need to create a monitor. A monitor is a container for tracking production events and their evaluations. In this example, the evaluations in the monitor will leverage a file as context, which will need to be uploaded first.
Tip: You can also create a monitor via the DeepRails API Console.
from deeprails import DeepRails, omit

# Initialize (env var DEEPRAILS_API_KEY is recommended)
client = DeepRails(api_key="YOUR_API_KEY")

try:

    with open("example.txt", "rb") as file:
        file_response = client.post(
            "/files/upload",
            cast_to=object,
            files={"files": file},
            options={"headers": {"Content-Type": omit}},
        )

    file_item = file_response[0] if isinstance(file_response, list) and file_response else file_response
    file_id = file_item.get("file_id") if isinstance(file_item, dict) else None
    if not file_id:
        raise ValueError("File upload failed")

    # Create a monitor
    monitor = client.monitor.create(
        name="Production Chat Assistant Monitor",
        description="Monitoring our production chatbot responses",
        guardrail_metrics=[
          "completeness",
          "correctness"
        ],
        web_search=True,
        file_search=[
          file_id
        ],
        context_awareness=True,
    )
    
    print(f"Monitor created:\n{monitor}")

except Exception as e:
    print(f"Error: {e}")
Required Parameters
FieldTypeDescription
namestringThe human-readable name of the monitor
guardrail_metricsstring[]A list of one or more metrics that events associated with this monitor will be evaluated on
Optional Parameters
FieldTypeDescription
descriptionstringA description of the monitor and/or the associated production use case
web_searchboolWhether or not web search is added as an extended capability for this monitor’s evaluations. Defaults to false
file_searchstring[]A list of file IDs to be used for file search in this monitor’s evaluations. If nothing is passed, file search will not be used
context_awarenessboolWhether or not context awareness is added as an extended capability for this monitor’s evaluations. Defaults to false

Send Your First Monitor Event

Use the SDK to log a production event (input + output). The SDK automatically triggers an evaluation of the guardrail metrics assigned to the monitor and links the result to the event. Retrieve the details of the event until it gives a completed status; then, you can view the outcome of the evaluation.
from deeprails import DeepRails
import time

# Initialize (env var DEEPRAILS_API_KEY is recommended)
client = DeepRails(api_key="YOUR_API_KEY")

# Create a monitor event (get the monitor_id from Console → Monitors)
created = client.monitor.submit_event(
    monitor_id="mon_xxxxxxxxxxxx",
    model_input={
        "system_prompt": "You are a helpful tutor specializing in AP science classes.",
        "user_prompt": "Explain the difference between mitosis and meiosis in one sentence.",
        "context": [{"role": "user", "content": "I have an AP Bio exam tomorrow, can you help me study?"}, {"role": "tutor", "content": "Sure, I'll help you study."}]
    },
    model_output="Mitosis produces two genetically identical diploid cells for growth and tissue repair, whereas meiosis generates four genetically varied haploid gametes for sexual reproduction.",
    run_mode="fast",
)

print(created)

time.sleep(5)

status = ""
while status != "completed":
  time.sleep(1)
  event = client.monitor.retrieve_event(event_id=created.event_id, monitor_id=created.monitor_id)
  status = event.status

print(event.evaluation_result)

Required Parameters
FieldTypeDescription
monitor_idstringThe ID of the monitor to receive the event (find it in Console → Monitor → Manage Monitors).
model_inputobjectMust include at least a user_prompt.
model_outputstringThe LLM output to be evaluated and recorded with the event.
Optional Parameters
FieldTypeDescription
run_modestringRun mode for the monitor event that determines which models are used to evaluate the event. Available run modes include precision_max_codex, precision_max, precision_codex, precision, and fast. Defaults to precision.

Retrieve Monitor and Event Details

You can retrieve a monitor’s details via API including a list of recent events and stats on associated evaluation progress.
from deeprails import DeepRails

client = DeepRails(api_key="YOUR_API_KEY")

try:
    # Get monitor details
    monitor = client.monitor.retrieve(monitor_id="mon_xxxxxxxxxxxx")
    print(monitor)
except Exception as e:
    print(f"Error: {e}")

Check Monitor Analytics via the API Console

  1. Open DeepRails API Console → Monitor → Data.
  2. Filter by model, time range, or search by monitor_id to find events.
  3. Open any event to see the linked evaluation scores and rationales.
Monitor data – placeholder

Browse real-time monitor events, filters, and linked evaluation details.

Next Steps