[QUESTION] How can I know if the session has ended from the server API? #2030

Closed
opened 2026-02-16 17:33:49 -05:00 by yindo · 4 comments
Owner

Originally created by @dayeguilaiye on GitHub (Oct 10, 2025).

Originally assigned to: @rekram1-node on GitHub.

When I send a prompt to the opencode server via API, how should I know if opencode has completed this operation?
I tried GET /sessions, GET /sessions/{id}, GET /sessions/{id}/message, but from the return values, it seems none of them indicate whether the AI's response has ended.
Did I miss something, or should I use a different interface to know this?

Originally created by @dayeguilaiye on GitHub (Oct 10, 2025). Originally assigned to: @rekram1-node on GitHub. When I send a prompt to the `opencode server` via API, how should I know if opencode has completed this operation? I tried `GET /sessions`, `GET /sessions/{id}`, `GET /sessions/{id}/message`, but from the return values, it seems none of them indicate whether the AI's response has ended. Did I miss something, or should I use a different interface to know this?
yindo closed this issue 2026-02-16 17:33:49 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 10, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #2168: Similar question about API documentation and expected flow for session endpoints, specifically asking about how to determine when AI response has ended and proper polling patterns

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 10, 2025): This issue might be a duplicate of existing issues. Please check: - #2168: Similar question about API documentation and expected flow for session endpoints, specifically asking about how to determine when AI response has ended and proper polling patterns Feel free to ignore if none of these address your specific case.
Author
Owner

@OpeOginni commented on GitHub (Oct 10, 2025):

@dayeguilaiye are you able to get the messageID of the response?

Also I feel like if you do get a response after sending the prompt, that is your indication that the operation is completed. Not sure you will get a response without OpenCode being done.

@OpeOginni commented on GitHub (Oct 10, 2025): @dayeguilaiye are you able to get the messageID of the response? Also I feel like if you do get a response after sending the prompt, that is your indication that the operation is completed. Not sure you will get a response without OpenCode being done.
Author
Owner

@rekram1-node commented on GitHub (Oct 10, 2025):

@dayeguilaiye if u send a request to /session/${sessionId}/message the request is finished after llm finishes... isn't that the best indicator here?

EX:

#!/bin/bash

BASE_URL="http://127.0.0.1:55028"

echo "Creating session..."
SESSION_RESPONSE=$(curl -s -X POST "$BASE_URL/session" \
  -H "Content-Type: application/json" \
  -d '{"title": "Test Session"}')

SESSION_ID=$(echo "$SESSION_RESPONSE" | jq -r '.id')
echo "Created session: $SESSION_ID"

echo -e "\nSending prompt..."
PROMPT_RESPONSE=$(curl -s -X POST "$BASE_URL/session/$SESSION_ID/message" \
  -H "Content-Type: application/json" \
  -d '{
    "parts": [
      {
        "type": "text",
        "text": "Hello! Can you help me understand how this works?"
      }
    ],
    "model": {
      "providerID": "openai",
      "modelID": "gpt-4"
    }
  }')

echo -e "\nResponse:"
echo "$PROMPT_RESPONSE" | jq '.'

echo -e "\nGetting all messages..."
MESSAGES_RESPONSE=$(curl -s -X GET "$BASE_URL/session/$SESSION_ID/message")
echo "$MESSAGES_RESPONSE" | jq '.'
@rekram1-node commented on GitHub (Oct 10, 2025): @dayeguilaiye if u send a request to /session/${sessionId}/message the request is finished after llm finishes... isn't that the best indicator here? EX: ``` #!/bin/bash BASE_URL="http://127.0.0.1:55028" echo "Creating session..." SESSION_RESPONSE=$(curl -s -X POST "$BASE_URL/session" \ -H "Content-Type: application/json" \ -d '{"title": "Test Session"}') SESSION_ID=$(echo "$SESSION_RESPONSE" | jq -r '.id') echo "Created session: $SESSION_ID" echo -e "\nSending prompt..." PROMPT_RESPONSE=$(curl -s -X POST "$BASE_URL/session/$SESSION_ID/message" \ -H "Content-Type: application/json" \ -d '{ "parts": [ { "type": "text", "text": "Hello! Can you help me understand how this works?" } ], "model": { "providerID": "openai", "modelID": "gpt-4" } }') echo -e "\nResponse:" echo "$PROMPT_RESPONSE" | jq '.' echo -e "\nGetting all messages..." MESSAGES_RESPONSE=$(curl -s -X GET "$BASE_URL/session/$SESSION_ID/message") echo "$MESSAGES_RESPONSE" | jq '.' ```
Author
Owner

@dayeguilaiye commented on GitHub (Oct 10, 2025):

@OpeOginni @rekram1-node Thank you very much for your reply. I didn't realize that POST /session/{id}/message is a synchronous interface; I thought it was asynchronous. So as long as this interface doesn't return, it means the agent is still running.

@dayeguilaiye commented on GitHub (Oct 10, 2025): @OpeOginni @rekram1-node Thank you very much for your reply. I didn't realize that `POST /session/{id}/message` is a synchronous interface; I thought it was asynchronous. So as long as this interface doesn't return, it means the agent is still running.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2030