Skip to content

Comments

fix: send empty JSON body in session.create()#44

Open
illera88 wants to merge 1 commit intoanomalyco:mainfrom
illera88:fix/session-create-empty-body
Open

fix: send empty JSON body in session.create()#44
illera88 wants to merge 1 commit intoanomalyco:mainfrom
illera88:fix/session-create-empty-body

Conversation

@illera88
Copy link

Summary

  • session.create() (both sync and async) now sends body={} so that the HTTP request includes Content-Type: application/json with an empty JSON object.

Problem

The OpenCode server's POST /session endpoint requires a JSON request body. When create() is called without any parameters, the SDK sends a POST with no body, causing the server to respond with 400 Malformed JSON in request body.

Reproduction

from opencode_ai import Opencode

client = Opencode(base_url="http://127.0.0.1:4096")
session = client.session.create()  # raises BadRequestError

Current workaround

session = client.session.create(extra_body={})

Fix

Added body={} to the self._post() calls in both SessionResource.create() and AsyncSessionResource.create(). This ensures the SDK always sends a valid empty JSON object when no session parameters (like title or parentID) are provided.

The OpenCode server's POST /session endpoint requires a JSON request
body (Content-Type: application/json), even when no parameters are
provided. Without a body, the server returns 400 'Malformed JSON in
request body'.

Both the sync and async create() methods now send body={} so that the
SDK serializes an empty JSON object, matching what the server expects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant