Skip to content

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

Closed

Description

@dayeguilaiye

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?

Activity

  1. github-actions commented on Oct 10, 2025

    @github-actions
    Contributor

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

    • [question] API documentation #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.

  2. OpeOginni commented on Oct 10, 2025

    @OpeOginni
    Contributor

    @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.

  3. self-assigned this
    on Oct 10, 2025
  4. rekram1-node commented on Oct 10, 2025

    @rekram1-node
    Contributor

    @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 '.'
    
  5. dayeguilaiye commented on Oct 11, 2025

    @dayeguilaiye
    Author

    @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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions