Prompt Templates

The Prompt Templates API allows you to manage templates and their associated versions.

Get latest version of a Prompt Template

This is the most common endpoint you'll use when working with prompt templates.

This route is used by the Lunary SDK sto fetch the latest version of a template before making an LLM call.

This route differs from all the next ones in that:

  • it requires only the slug parameter to reference a template
  • it doesn't require using a Private Key to authenticate the request (Public Key is enough)
GET/v1/template_versions/latest
curl -X GET "https://api.lunary.ai/v1/template_versions/latest?slug=example-template" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <api_key>"

Accepted Keys:

slug

Example response for /v1/template_versions/latest:

{
"id": 2999,
"slug": "example-template",
"templateId": "template-123",
"content": [
{
"role": "system",
"content": "You are an assistant"
},
{
"role": "user",
"content": "Hello world! My question is {{question}}"
}
],
"extra": {
"model": "gpt-4o",
"max_tokens": 1000,
"temperature": 0.5,
"tools": []
},
"isDraft": false,
"createdAt": "2023-01-01T00:00:00Z"
}

If you are then reporting the results of the LLM call, you can add the templateVersionId field to reference the template used in the call.

List All Prompt Templates

List all the prompt templates in your project, along with their versions.

Useful for usecases where you might want to pre-load all the templates in your application.

GET/v1/templates
curl -X GET "https://api.lunary.ai/v1/templates" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <api_key>"

Example response for /v1/templates:

[
{
"id": 12356,
"name": "Example Template",
"slug": "example-template",
"mode": "openai",
"createdAt": "2023-01-01T00:00:00Z",
"projectId": "0000-0000-0000-0000",
"versions": [
{
"id": 2999,
"templateId": "template-123",
"content": [
{
"role": "system",
"content": "You are an assistant"
},
{
"role": "user",
"content": "Hello world! My question is {{question}}"
},
{
"role": "assistant",
"content": "Hello. How are you?"
}
],
"extra": {
"model": "gpt-4-turbo",
"max_tokens": 1000,
"temperature": 0.5,
"tools": []
},
"testValues": {
"question": "What is the meaning of life?"
},
"isDraft": false,
"createdAt": "2023-01-01T00:00:00Z"
}
]
}
]

Get a Prompt Template

GET/v1/templates/:slug
curl -X GET "https://api.lunary.ai/v1/templates/:slug" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <api_key>"

Example response for /v1/templates/:slug:

{
"id": "template-456",
"projectId": "project-789",
"ownerId": "owner-123",
"slug": "new-template",
"mode": "chat",
"createdAt": "2023-01-02T00:00:00Z"
}

Create Prompt Template

POST/v1/templates
curl -X POST "https://api.lunary.ai/v1/templates" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <api_key>" \
-d '{
"slug": "new-template",
"mode": "chat",
"content": [
{
"role": "system",
"content": "You are an assistant"
},
{
"role": "user",
"content": "Hello world! My question is {{question}}"
}
],
"extra": {
"temperature": 0.7,
"tools": []
},
"testValues": {},
"isDraft": false
}'

Accepted Keys:

slug
mode
content
extra
testValues
isDraft

Example response for /v1/templates:

{
"id": "template-456",
"projectId": "project-789",
"ownerId": "owner-123",
"slug": "new-template",
"mode": "chat",
"versions": [
{
"id": "version-101",
"templateId": "template-456",
"content": [
{
"role": "system",
"content": "You are an assistant"
},
{
"role": "user",
"content": "Hello world! My question is {{question}}"
}
],
"extra": {
"temperature": 0.7,
"tools": []
},
"testValues": {},
"isDraft": false,
"createdAt": "2023-01-02T00:00:00Z",
"version": 1
}
]
}

Delete Prompt Template

DELETE/v1/templates/:id
curl -X DELETE "https://api.lunary.ai/v1/templates/:id" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <api_key>"

Update Prompt Template

PATCH/v1/templates/:id
curl -X PATCH "https://api.lunary.ai/v1/templates/:id" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <api_key>" \
-d '{
"slug": "updated-template",
"mode": "chat"
}'

Accepted Keys:

slug
mode

Example response for /v1/templates/:id:

{
"id": "template-456",
"projectId": "project-789",
"ownerId": "owner-123",
"slug": "updated-template",
"mode": "chat",
"createdAt": "2023-01-02T00:00:00Z",
"versions": [
{
"id": "version-101",
"templateId": "template-456",
"content": [
{
"role": "system",
"content": "You are an assistant"
},
{
"role": "user",
"content": "Hello world! My question is {{question}}"
}
],
"extra": {
"temperature": 0.7,
"tools": []
},
"testValues": {},
"isDraft": false,
"createdAt": "2023-01-02T00:00:00Z",
"version": 1
}
]
}

Create Template Version

POST/v1/templates/:id/versions
curl -X POST "https://api.lunary.ai/v1/templates/:id/versions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <api_key>" \
-d '{
"content": [
{
"role": "system",
"content": "You are an assistant"
},
{
"role": "user",
"content": "Hello world! My question is {{question}}"
}
],
"extra": {
"temperature": 0.7,
"tools": []
},
"testValues": {},
"isDraft": false
}'

Accepted Keys:

content
extra
testValues
isDraft

Example response for /v1/templates/:id/versions:

{
"id": "version-102",
"templateId": "template-456",
"content": [
{
"role": "system",
"content": "You are an assistant"
},
{
"role": "user",
"content": "Hello world! My question is {{question}}"
}
],
"extra": {
"temperature": 0.7,
"tools": []
},
"testValues": {},
"isDraft": false,
"createdAt": "2023-01-03T00:00:00Z",
"version": 2
}

Questions? We're here to help.