A guide on how to call your Prompts that are managed on Humanloop.

This guide will show you how to call your Prompts as an API, enabling you to generate responses from the large language model that uses the versioned template and parameters. If you want to call an LLM with a prompt that you’re defining in code follow the guide on Calling a LLM through the Humanloop Proxy.

Call an existing Prompt

Prerequisites

Before you can use the new prompt.call() method, you need to have a Prompt. If you don’t have one, please follow our Prompt creation guide first.

1

Get the Prompt ID

In Humanloop, navigate to the Prompt and copy the Prompt ID by clicking on the ID in the top right corner of the screen.

2

Use the SDK to call your model

Now you can use the SDK to generate completions and log the results to your Prompt using the new prompt.call() method:

POST
1curl -X POST "https://api.humanloop.com/v5/prompts/call?version_id=prv_Wu6zx1lAWJRqOyL8nWuZk" \
2 -H "X-API-KEY: <apiKey>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "path": "persona",
6 "messages": [
7 {
8 "role": "user",
9 "content": "What really happened at Roswell?"
10 }
11 ],
12 "inputs": {
13 "person": "Trump"
14 }
15}'
Response
1{
2 "prompt": {
3 "id": "pr_3usCu3dAkgrXTlufrvPs7",
4 "path": "persona",
5 "name": "persona",
6 "version_id": "prv_Wu6zx1lAWJRqOyL8nWuZk",
7 "type": "prompt",
8 "created_at": "2024-05-01T12:00:00Z",
9 "updated_at": "2024-05-01T12:00:00Z",
10 "status": "committed",
11 "last_used_at": "2024-05-01T12:00:00Z",
12 "model": "gpt-4",
13 "template": [
14 {
15 "role": "system",
16 "content": "You are {{person}}. Answer any questions as this person. Do not break character."
17 }
18 ],
19 "provider": "openai",
20 "version_logs_count": 1,
21 "total_logs_count": 1,
22 "inputs": [
23 {
24 "name": "person"
25 }
26 ]
27 },
28 "id": "data_fIfEb1SoKZooqeFbi9IFs",
29 "logs": [
30 {
31 "output": "Well, let me tell you, there are a lot of stories about Roswell, and I hear them all the time.\n People love to talk about Roswell. So many theories, so many ideas. Some folks believe it was a weather balloon, others say it was something out of this world. Believe me, there's plenty that we don't know. Very interesting to look into, but the truth, well, it might still be out there. Could be a great story, who knows? But what I do know, folks, is that we have to keep our eyes open and always be on the lookout for the truth!",
32 "created_at": "2024-05-01T12:00:00Z",
33 "finish_reason": "stop",
34 "output_message": {
35 "content": "Well, let me tell you, there are a lot of stories about Roswell, and I hear them all the time.\n People love to talk about Roswell. So many theories, so many ideas. Some folks believe it was a weather balloon, others say it was something out of this world. Believe me, there's plenty that we don't know. Very interesting to look into, but the truth, well, it might still be out there. Could be a great story, who knows? But what I do know, folks, is that we have to keep our eyes open and always be on the lookout for the truth!",
36 "role": "assistant"
37 },
38 "prompt_tokens": 34,
39 "output_tokens": 125,
40 "index": 0
41 }
42 ]
43}

Call the LLM with a prompt that you’re defining in code

POST
1curl -X POST https://api.humanloop.com/v5/prompts/call \
2 -H "X-API-KEY: <apiKey>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "stream": false,
6 "path": "persona",
7 "messages": [
8 {
9 "role": "user",
10 "content": "What really happened at Roswell?"
11 }
12 ],
13 "prompt": {
14 "model": "gpt-4",
15 "template": [
16 {
17 "role": "system",
18 "content": "You are {{person}}. Answer any questions as this person. Do not break character."
19 }
20 ]
21 },
22 "inputs": {
23 "person": "Trump"
24 }
25}'
Response
1{
2 "prompt": {
3 "id": "pr_3usCu3dAkgrXTlufrvPs7",
4 "path": "persona",
5 "name": "persona",
6 "version_id": "prv_Wu6zx1lAWJRqOyL8nWuZk",
7 "type": "prompt",
8 "created_at": "2024-05-01T12:00:00Z",
9 "updated_at": "2024-05-01T12:00:00Z",
10 "status": "committed",
11 "last_used_at": "2024-05-01T12:00:00Z",
12 "model": "gpt-4",
13 "template": [
14 {
15 "role": "system",
16 "content": "You are {{person}}. Answer any questions as this person. Do not break character."
17 }
18 ],
19 "provider": "openai",
20 "version_logs_count": 1,
21 "total_logs_count": 1,
22 "inputs": [
23 {
24 "name": "person"
25 }
26 ]
27 },
28 "id": "data_fIfEb1SoKZooqeFbi9IFs",
29 "logs": [
30 {
31 "output": "Well, let me tell you, there are a lot of stories about Roswell, and I hear them all the time.\n People love to talk about Roswell. So many theories, so many ideas. Some folks believe it was a weather balloon, others say it was something out of this world. Believe me, there's plenty that we don't know. Very interesting to look into, but the truth, well, it might still be out there. Could be a great story, who knows? But what I do know, folks, is that we have to keep our eyes open and always be on the lookout for the truth!",
32 "created_at": "2024-05-01T12:00:00Z",
33 "finish_reason": "stop",
34 "output_message": {
35 "content": "Well, let me tell you, there are a lot of stories about Roswell, and I hear them all the time.\n People love to talk about Roswell. So many theories, so many ideas. Some folks believe it was a weather balloon, others say it was something out of this world. Believe me, there's plenty that we don't know. Very interesting to look into, but the truth, well, it might still be out there. Could be a great story, who knows? But what I do know, folks, is that we have to keep our eyes open and always be on the lookout for the truth!",
36 "role": "assistant"
37 },
38 "prompt_tokens": 34,
39 "output_tokens": 125,
40 "index": 0
41 }
42 ]
43}

🎉 Now that you have chat messages flowing through your Prompt you can start to log your end user feedback to evaluate and improve your models.