Relay Assistants API
2024.1.4 This relay now supports the Assistants API
Notes
- Supports
Code InterpreterandFunction calling
- Supports
Knowledge Retrievalis not yet supported
- Billing includes both token costs and conversation thread fees
- Accounts may go offline for unforeseen reasons, so
assistants id,thread id, andrun idcannot be guaranteed to remain available indefinitely
- Accounts may go offline for unforeseen reasons, so
Reference Documentation
1. Create an Assistant
shell
curl "https://api.openai-hk.com/v1/assistants" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer hk-your-key" \
-H "OpenAI-Beta: assistants=v1" \
-d '{
"instructions": "You are a personal math tutor. Write and run code to answer math questions.",
"name": "Math Tutor",
"tools": [{"type": "code_interpreter"}],
"model": "gpt-4"
}'curl "https://api.openai-hk.com/v1/assistants" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer hk-your-key" \
-H "OpenAI-Beta: assistants=v1" \
-d '{
"instructions": "You are a personal math tutor. Write and run code to answer math questions.",
"name": "Math Tutor",
"tools": [{"type": "code_interpreter"}],
"model": "gpt-4"
}'Response body
json
{
"id": "asst_AXBqN2YyydsTQcdhxNN22Sy5", //this is used in the run step
"object": "assistant",
"created_at": 1704298806,
"name": "Math Tutor",
"description": null,
"model": "gpt-4",
"instructions": "You are a personal math tutor. Write and run code to answer math questions.",
"tools": [
{
"type": "code_interpreter"
}
],
"file_ids": [],
"metadata": {}
}{
"id": "asst_AXBqN2YyydsTQcdhxNN22Sy5", //this is used in the run step
"object": "assistant",
"created_at": 1704298806,
"name": "Math Tutor",
"description": null,
"model": "gpt-4",
"instructions": "You are a personal math tutor. Write and run code to answer math questions.",
"tools": [
{
"type": "code_interpreter"
}
],
"file_ids": [],
"metadata": {}
}2. Create a Thread (Conversation)
Must use POST
shell
curl https://api.openai-hk.com/v1/threads \
-H "Content-Type: application/json" \
-H "Authorization: Bearer hk-your-key" \
-H "OpenAI-Beta: assistants=v1" \
-d ''curl https://api.openai-hk.com/v1/threads \
-H "Content-Type: application/json" \
-H "Authorization: Bearer hk-your-key" \
-H "OpenAI-Beta: assistants=v1" \
-d ''Response
json
{
"id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f", //used in all subsequent steps
"object": "thread",
"created_at": 1704298816,
"metadata": {}
}{
"id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f", //used in all subsequent steps
"object": "thread",
"created_at": 1704298816,
"metadata": {}
}3. Add a Message to the Thread
shell
curl https://api.openai-hk.com/v1/threads/thread_PRhqIIzk5g2IKjTdo7jsLd5f/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer hk-your-key" \
-H "OpenAI-Beta: assistants=v1" \
-d '{
"role": "user",
"content": "What is the vertex of y=-5x^2+7x+89?"
}'curl https://api.openai-hk.com/v1/threads/thread_PRhqIIzk5g2IKjTdo7jsLd5f/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer hk-your-key" \
-H "OpenAI-Beta: assistants=v1" \
-d '{
"role": "user",
"content": "What is the vertex of y=-5x^2+7x+89?"
}'Response body
json
{
"id": "msg_baXqZT49fuB7nSp2uDaDcxay",
"object": "thread.message",
"created_at": 1704301942,
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "y=-5x^2+7x+89 顶点是多少?",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": null,
"run_id": null,
"metadata": {}
}{
"id": "msg_baXqZT49fuB7nSp2uDaDcxay",
"object": "thread.message",
"created_at": 1704301942,
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "y=-5x^2+7x+89 顶点是多少?",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": null,
"run_id": null,
"metadata": {}
}4. Run
The assistant_id from step 2 is used here
shell
curl https://api.openai-hk.com/v1/threads/thread_PRhqIIzk5g2IKjTdo7jsLd5f/runs \
-H "Authorization: Bearer hk-your-key" \
-H "Content-Type: application/json" \
-H "OpenAI-Beta: assistants=v1" \
-d '{
"assistant_id": "asst_AXBqN2YyydsTQcdhxNN22Sy5",
"instructions": "Please address the user as Jane Doe. The user has a premium account."
}'curl https://api.openai-hk.com/v1/threads/thread_PRhqIIzk5g2IKjTdo7jsLd5f/runs \
-H "Authorization: Bearer hk-your-key" \
-H "Content-Type: application/json" \
-H "OpenAI-Beta: assistants=v1" \
-d '{
"assistant_id": "asst_AXBqN2YyydsTQcdhxNN22Sy5",
"instructions": "Please address the user as Jane Doe. The user has a premium account."
}'Response
json
{
"id": "run_8eBTGBWCmUEZICJyu7wEtUCt",
"object": "thread.run",
"created_at": 1704301949,
"assistant_id": "asst_AXBqN2YyydsTQcdhxNN22Sy5",
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"status": "queued",
"started_at": null,
"expires_at": 1704302549,
"cancelled_at": null,
"failed_at": null,
"completed_at": null,
"last_error": null,
"model": "gpt-4",
"instructions": "Please address the user as Jane Doe. The user has a premium account.",
"tools": [
{
"type": "code_interpreter"
}
],
"file_ids": [],
"metadata": {}
}{
"id": "run_8eBTGBWCmUEZICJyu7wEtUCt",
"object": "thread.run",
"created_at": 1704301949,
"assistant_id": "asst_AXBqN2YyydsTQcdhxNN22Sy5",
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"status": "queued",
"started_at": null,
"expires_at": 1704302549,
"cancelled_at": null,
"failed_at": null,
"completed_at": null,
"last_error": null,
"model": "gpt-4",
"instructions": "Please address the user as Jane Doe. The user has a premium account.",
"tools": [
{
"type": "code_interpreter"
}
],
"file_ids": [],
"metadata": {}
}5. Check Status
shell
curl https://api.openai-hk.com/v1/threads/thread_PRhqIIzk5g2IKjTdo7jsLd5f/runs/run_8eBTGBWCmUEZICJyu7wEtUCt \
-H "Authorization: Bearer hk-your-key" \
-H "OpenAI-Beta: assistants=v1"curl https://api.openai-hk.com/v1/threads/thread_PRhqIIzk5g2IKjTdo7jsLd5f/runs/run_8eBTGBWCmUEZICJyu7wEtUCt \
-H "Authorization: Bearer hk-your-key" \
-H "OpenAI-Beta: assistants=v1"6. Retrieve Results
shell
curl https://api.openai-hk.com/v1/threads/thread_PRhqIIzk5g2IKjTdo7jsLd5f/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer hk-your-key" \
-H "OpenAI-Beta: assistants=v1"curl https://api.openai-hk.com/v1/threads/thread_PRhqIIzk5g2IKjTdo7jsLd5f/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer hk-your-key" \
-H "OpenAI-Beta: assistants=v1"Result content:
json
{
"object": "list",
"data": [
{
"id": "msg_oNRxXuvkaMpbkcEIpOmgvpVO",
"object": "thread.message",
"created_at": 1704299111,
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "这个二次函数的顶点纵坐标为约 89.8。因此,这个二次函数的顶点为 (2/5, 89.8)。",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": "asst_AXBqN2YyydsTQcdhxNN22Sy5",
"run_id": "run_lIpFnVSVSWmlBmdtL0I2p3Mx",
"metadata": {}
},
{
"id": "msg_Ho2FvaWxhdiPQwxXSFTZEYc2",
"object": "thread.message",
"created_at": 1704299107,
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "这个二次函数的顶点横坐标为 2/5。接下来,我们可以将 x = 2/5 代入原方程,求得纵坐标。",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": "asst_AXBqN2YyydsTQcdhxNN22Sy5",
"run_id": "run_lIpFnVSVSWmlBmdtL0I2p3Mx",
"metadata": {}
},
{
"id": "msg_wWIkXbSbb2ClY4y6TGgOu183",
"object": "thread.message",
"created_at": 1704299100,
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "您想要找到这个二次函数的顶点吗?",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": "asst_AXBqN2YyydsTQcdhxNN22Sy5",
"run_id": "run_lIpFnVSVSWmlBmdtL0I2p3Mx",
"metadata": {}
},
{
"id": "msg_j0c12LisQjAIDjZYQGTrgqtu",
"object": "thread.message",
"created_at": 1704298850,
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "y=-5x^2+4x+89 定点是多少?",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": null,
"run_id": null,
"metadata": {}
}
],
"first_id": "msg_oNRxXuvkaMpbkcEIpOmgvpVO",
"last_id": "msg_j0c12LisQjAIDjZYQGTrgqtu",
"has_more": false
}{
"object": "list",
"data": [
{
"id": "msg_oNRxXuvkaMpbkcEIpOmgvpVO",
"object": "thread.message",
"created_at": 1704299111,
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "这个二次函数的顶点纵坐标为约 89.8。因此,这个二次函数的顶点为 (2/5, 89.8)。",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": "asst_AXBqN2YyydsTQcdhxNN22Sy5",
"run_id": "run_lIpFnVSVSWmlBmdtL0I2p3Mx",
"metadata": {}
},
{
"id": "msg_Ho2FvaWxhdiPQwxXSFTZEYc2",
"object": "thread.message",
"created_at": 1704299107,
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "这个二次函数的顶点横坐标为 2/5。接下来,我们可以将 x = 2/5 代入原方程,求得纵坐标。",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": "asst_AXBqN2YyydsTQcdhxNN22Sy5",
"run_id": "run_lIpFnVSVSWmlBmdtL0I2p3Mx",
"metadata": {}
},
{
"id": "msg_wWIkXbSbb2ClY4y6TGgOu183",
"object": "thread.message",
"created_at": 1704299100,
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "您想要找到这个二次函数的顶点吗?",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": "asst_AXBqN2YyydsTQcdhxNN22Sy5",
"run_id": "run_lIpFnVSVSWmlBmdtL0I2p3Mx",
"metadata": {}
},
{
"id": "msg_j0c12LisQjAIDjZYQGTrgqtu",
"object": "thread.message",
"created_at": 1704298850,
"thread_id": "thread_PRhqIIzk5g2IKjTdo7jsLd5f",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "y=-5x^2+4x+89 定点是多少?",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": null,
"run_id": null,
"metadata": {}
}
],
"first_id": "msg_oNRxXuvkaMpbkcEIpOmgvpVO",
"last_id": "msg_j0c12LisQjAIDjZYQGTrgqtu",
"has_more": false
}
OpenAi-HK