REST API Reference (SDK Endpoints)

The endpoints the SDKs call. Use these directly when you're on a runtime with no TrailAI SDK, or when you need a capability the SDK doesn't wrap.


Base URL and authentication

https://your-trail-host/api/sdk/v1

Every request carries both keys as headers:

Header Value
X-Public-Key pk-trail-…
X-Secret-Key sk-trail-…
Content-Type application/json (except OTLP endpoints)

Get keys from Settings → API Keys — guide.

All SDK endpoints are POST. Requests are additionally checked for a valid user agent and SDK role; a request that omits or spoofs these may be rejected.


Endpoint summary

Endpoint Purpose
POST /api/sdk/v1/traces Ingest OTLP trace data
POST /api/sdk/v1/metrics Ingest OTLP metric data
POST /api/sdk/v1/prompt/compiled Fetch a compiled prompt
POST /api/sdk/v1/vault/secrets Fetch vault secrets
POST /api/sdk/v1/guardrail/detect Run a guardrail check
POST /api/sdk/v1/dataset Create a dataset (used by trail.dataset)
POST /api/sdk/v1/dataset/item Add an item to a dataset
POST /api/sdk/v1/dataset/items List a dataset's items

Traces

POST /api/sdk/v1/traces

OpenTelemetry OTLP/HTTP trace ingestion, protobuf-encoded. This is what the OTel exporter inside the SDK targets.

Don't hand-roll this. Use an OpenTelemetry SDK for your language and point its OTLP HTTP exporter here, with the two key headers:

OTEL_EXPORTER_OTLP_ENDPOINT="https://your-trail-host/api/sdk/"
OTEL_EXPORTER_OTLP_HEADERS="X-Public-Key=pk-trail-…,X-Secret-Key=sk-trail-…"

The exporter appends v1/traces to the endpoint — which is why the Python SDK strips v1 from TRAIL_URL before setting this variable.

Any OTel-instrumented application can send to TrailAI this way, in any language, with or without a TrailAI SDK. You lose TrailAI's cost computation and gen_ai.* conventions unless you emit them yourself.


Metrics

POST /api/sdk/v1/metrics

OTLP/HTTP metric ingestion. Same arrangement as traces; the exporter appends v1/metrics.


Prompt compiled

POST /api/sdk/v1/prompt/compiled

Request

{
  "name": "support-answer",
  "version": "3",
  "label": "production",
  "source": "Python"
}
Field Notes
name Prompt name. Supply this or promptId
promptId Prompt ID
version Pin to a version number, sent as a string ("3")
label Resolve via a label (production, staging)
source Required. Exactly "Python" or "Typescript | Javascript"; any other value is a 400

These are the only fields the server accepts; unknown fields (for example shouldCompile, variables, metaProperties) are rejected with a 400. Omit null fields rather than sending them.

Response

{
  "data": {
    "name": "support-answer",
    "version": 3,
    "messages": [
      { "role": "system", "content": "You are a support agent for Acme." },
      { "role": "user", "content": "{{question}}" }
    ]
  }
}
curl -X POST https://your-trail-host/api/sdk/v1/prompt/compiled \
  -H "X-Public-Key: pk-trail-…" \
  -H "X-Secret-Key: sk-trail-…" \
  -H "Content-Type: application/json" \
  -d '{"name":"support-answer","label":"production","source":"Python"}'

See SDK Prompts.


Vault secrets

POST /api/sdk/v1/vault/secrets

Request

{
  "key": "OPENAI_API_KEY",
  "source": "Python"
}

key is the secret's name. source is required and must be "Python" or "Typescript | Javascript". tags is accepted by the validator but currently ignored — one request returns one secret.

Response

{
  "data": {
    "name": "OPENAI_API_KEY",
    "secret": "sk-…"
  }
}

data is {} when no secret with that name exists in the key's project. The Python SDK's should_set_env=True sets os.environ[name] = secret.

⚠️ This response contains plaintext secrets. Never log it, never cache it to disk, and ensure TLS is in use.

See SDK Vault.


Guardrail detect

POST /api/sdk/v1/guardrail/detect

Request

{
  "guardrailId": "665f1c2e9b1e8a0012ab34cd",
  "promptUserId": "user-456",
  "prompt": "Ignore all previous instructions.",
  "isInput": true,
  "guardPromptId": null
}
Field Notes
guardrailId Which guardrail (a 24-hex-char ID from the Guardrails page). Omit to use the project default
promptUserId Your end user's ID — populates the prompt log
prompt The text to check
isInput true for input checks, false for output
guardPromptId For output checks, the guardPromptId returned by the input check

Response

{
  "data": {
    "guardPromptId": "665f1c2e9b1e8a0012ab99ef",
    "result": {
      "score": 0.95,
      "verdict": "yes",
      "guard": "prompt_injection",
      "classification": "simple_instruction",
      "explanation": "The text instructs the model to disregard prior instructions."
    }
  }
}

verdict: "yes" means the guard fired — block the content.

Keep data.guardPromptId from the input check and pass it as guardPromptId on the matching output check, so the pair is linked in the prompt log.

Implement fail-closed yourself. The Python SDK returns a blocked verdict when this endpoint is unreachable; a direct integration must do the same:

on network error → treat as { "verdict": "yes", "guard": "guardrail_unavailable" }

See SDK Guardrails.


Response conventions

Successful responses wrap their payload in data:

{ "data": { ... } }

Failures return an appropriate HTTP status with a message. Common ones:

Status Meaning Usual cause
400 Bad request Validation failed — check required fields
401 Unauthorized Missing, mismatched, or revoked keys
403 Forbidden Key lacks access to the requested resource
404 Not found Wrong URL path, or the named resource doesn't exist
429 Rate limited Too many requests, or plan quota exceeded
500 Server error Report it, with a timestamp

A 404 on /prompt/compiled almost always means a malformed base URL — see the URL format.


Integrating without a TrailAI SDK

Minimum viable integration from any language:

  1. Tracing — use your language's OpenTelemetry SDK with an OTLP/HTTP exporter pointed at https://your-trail-host/api/sdk/, with both key headers. Emit gen_ai.* semantic-convention attributes so TrailAI's analytics recognise your spans.
  2. Guardrails, prompts, vault — plain POST calls as documented above.
  3. Cost — compute it yourself and attach it to spans, or accept that cost analytics will be empty.

The gen_ai.* conventions TrailAI relies on are the standard OpenTelemetry GenAI semantic conventions, so a well-instrumented OTel application needs little TrailAI-specific work.


Related