Skip to content
OpenCode
Esc
navigateopen⌘Jpreview

Create session

Create a session at the requested location.

POST/api/session
Request body
requiredapplication/json
idobject | any
Show properties
Any of:
object
object
any
any
agentstring | any
Show properties
Any of:
string
string
any
any
modelModel.Ref | any
Show properties
Any of:
Model.Ref
idstringrequired
providerIDstringrequired
variantstring
any
any
locationLocation.Ref | any
Show properties
Any of:
Location.Ref
directorystringrequired
workspaceIDobject
Show properties
object
any
any
Responses
200Success
dataSession.Inforequired
Show properties
idobjectrequired
Show properties
object
parentIDobject
Show properties
object
forkobject
Show properties
sessionIDobjectrequired
Show properties
object
messageIDobject
Show properties
object
projectIDstringrequired
agentstring
modelModel.Ref
Show properties
idstringrequired
providerIDstringrequired
variantstring
costMoney.USDrequired
tokensTokenUsage.Inforequired
Show properties
inputnumberrequired
outputnumberrequired
reasoningnumberrequired
cacheobjectrequired
Show properties
readnumberrequired
writenumberrequired
timeobjectrequired
Show properties
creatednumberrequired
updatednumberrequired
archivednumber
titlestringrequired
locationLocation.Refrequired
Show properties
directorystringrequired
workspaceIDobject
Show properties
object
subpathstring
revertSession.Revert
Show properties
messageIDobjectrequired
Show properties
object
partIDstring
snapshotstring
filesFileDiff.Info[]
Show properties
Array of FileDiff.Info
filestringrequired
patchstringrequired
additionsobjectrequired
Show properties
object
deletionsobjectrequired
Show properties
object
statusstringrequired
Allowed:addeddeletedmodified
400InvalidRequestError
_tagstringrequired
Allowed:InvalidRequestError
messagestringrequired
kindstring | any
Show properties
Any of:
string
string
any
any
fieldstring | any
Show properties
Any of:
string
string
any
any
401UnauthorizedError
_tagstringrequired
Allowed:UnauthorizedError
messagestringrequired
Request
curl -X POST "/api/session" \
  -H "Content-Type: application/json" \
  -d '{
  "id": {},
  "agent": "string",
  "model": {
    "id": "string",
    "providerID": "string",
    "variant": "string"
  },
  "location": {
    "directory": "string",
    "workspaceID": {}
  }
}'
Response
{
  "data": {
    "id": {},
    "parentID": {},
    "fork": {
      "sessionID": {},
      "messageID": {}
    },
    "projectID": "string",
    "agent": "string",
    "model": {
      "id": "string",
      "providerID": "string",
      "variant": "string"
    },
    "cost": 0,
    "tokens": {
      "input": 0,
      "output": 0,
      "reasoning": 0,
      "cache": {
        "read": 0,
        "write": 0
      }
    },
    "time": {
      "created": 0,
      "updated": 0,
      "archived": 0
    },
    "title": "string",
    "location": {
      "directory": "string",
      "workspaceID": {}
    },
    "subpath": "string",
    "revert": {
      "messageID": {},
      "partID": "string",
      "snapshot": "string",
      "files": [
        {
          "file": "string",
          "patch": "string",
          "additions": {},
          "deletions": {},
          "status": "added"
        }
      ]
    }
  }
}