Skip to main content

API Reference

The Scope API provides programmatic access to prompts and versions. This page covers authentication, conventions, and error handling for the SDK-facing endpoints.

Base URL

https://your-scope-url/api/v1

All endpoints are prefixed with /api/v1. Replace your-scope-url with your Scope instance hostname.

Authentication

The Scope API uses JWT bearer tokens for authentication. The SDK authenticates using API keys through a dedicated token endpoint.

API Key Authentication

For programmatic access (SDK, CI/CD, scripts), authenticate using API keys:

  1. Obtain a JWT token by sending your API key credentials to the SDK token endpoint:
# Exchange API key for a JWT token
curl -s -X POST https://your-scope-url/v1/auth/sdk-token \
-H "Content-Type: application/json" \
-d '{
"account_id": "'"$SCOPE_ACCOUNT_ID"'",
"key_id": "'"$SCOPE_KEY_ID"'",
"key_secret": "'"$SCOPE_KEY_SECRET"'"
}'

Request Body:

FieldTypeRequiredDescription
account_idstringYesYour Scope account identifier
key_idstringYesAPI key identifier
key_secretstringYesAPI key secret

Response:

{
"access_token": "eyJhbGciOiJ...",
"expires_in": 3600,
"token_type": "Bearer"
}
  1. Include the token in the Authorization header of all subsequent requests:
curl https://your-scope-url/api/v1/prompts/greeting/production \
-H "Authorization: Bearer $TOKEN"
info

The SDK handles token exchange and refresh automatically. You only need to manage tokens directly when calling the REST API without the SDK.

Token Lifecycle

  • Tokens have a limited lifetime (typically minutes to hours)
  • Refresh tokens before they expire using the token_refresh_buffer setting
  • The SDK refreshes tokens automatically (default: 60 seconds before expiry)

Content Type

All request and response bodies use JSON:

Content-Type: application/json

Error Responses

All errors follow a consistent format:

{
"code": "not_found",
"message": "Prompt 'greeting' not found"
}

HTTP Status Codes

CodeMeaning
200Success
400Bad Request — invalid input or validation error
401Unauthorized — missing or invalid token
403Forbidden — insufficient permissions
404Not Found — resource doesn't exist
500Internal Server Error

API Sections

  • Prompts — fetch prompt versions (production, latest, specific)

Next Steps

Was this page helpful?