Create Session
curl --request POST \
--url https://api.example.com/api/sessions \
--header 'Content-Type: application/json' \
--data '
{
"organizationId": "<string>",
"initialMessage": "<string>",
"repoUrl": "<string>",
"baseBranch": "<string>",
"model": "<string>"
}
'import requests
url = "https://api.example.com/api/sessions"
payload = {
"organizationId": "<string>",
"initialMessage": "<string>",
"repoUrl": "<string>",
"baseBranch": "<string>",
"model": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
organizationId: '<string>',
initialMessage: '<string>',
repoUrl: '<string>',
baseBranch: '<string>',
model: '<string>'
})
};
fetch('https://api.example.com/api/sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'organizationId' => '<string>',
'initialMessage' => '<string>',
'repoUrl' => '<string>',
'baseBranch' => '<string>',
'model' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/sessions"
payload := strings.NewReader("{\n \"organizationId\": \"<string>\",\n \"initialMessage\": \"<string>\",\n \"repoUrl\": \"<string>\",\n \"baseBranch\": \"<string>\",\n \"model\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/sessions")
.header("Content-Type", "application/json")
.body("{\n \"organizationId\": \"<string>\",\n \"initialMessage\": \"<string>\",\n \"repoUrl\": \"<string>\",\n \"baseBranch\": \"<string>\",\n \"model\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"organizationId\": \"<string>\",\n \"initialMessage\": \"<string>\",\n \"repoUrl\": \"<string>\",\n \"baseBranch\": \"<string>\",\n \"model\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"session": {}
}Sessions
Create Session
Create a new AI coding session. Optionally link a repository and provide an initial prompt.
POST
/
api
/
sessions
Create Session
curl --request POST \
--url https://api.example.com/api/sessions \
--header 'Content-Type: application/json' \
--data '
{
"organizationId": "<string>",
"initialMessage": "<string>",
"repoUrl": "<string>",
"baseBranch": "<string>",
"model": "<string>"
}
'import requests
url = "https://api.example.com/api/sessions"
payload = {
"organizationId": "<string>",
"initialMessage": "<string>",
"repoUrl": "<string>",
"baseBranch": "<string>",
"model": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
organizationId: '<string>',
initialMessage: '<string>',
repoUrl: '<string>',
baseBranch: '<string>',
model: '<string>'
})
};
fetch('https://api.example.com/api/sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'organizationId' => '<string>',
'initialMessage' => '<string>',
'repoUrl' => '<string>',
'baseBranch' => '<string>',
'model' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/sessions"
payload := strings.NewReader("{\n \"organizationId\": \"<string>\",\n \"initialMessage\": \"<string>\",\n \"repoUrl\": \"<string>\",\n \"baseBranch\": \"<string>\",\n \"model\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/sessions")
.header("Content-Type", "application/json")
.body("{\n \"organizationId\": \"<string>\",\n \"initialMessage\": \"<string>\",\n \"repoUrl\": \"<string>\",\n \"baseBranch\": \"<string>\",\n \"model\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"organizationId\": \"<string>\",\n \"initialMessage\": \"<string>\",\n \"repoUrl\": \"<string>\",\n \"baseBranch\": \"<string>\",\n \"model\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"session": {}
}Authentication
Requires browser authentication (dashboard). API keys cannot create sessions — sessions must be attributed to a specific user.Request body
string
required
The ID of the workspace to create the session in.
string
The initial prompt for the agent. A title is auto-generated from this message.
string
GitHub repository URL to clone (e.g.,
https://github.com/owner/repo). The sandbox will clone this repo before the agent starts working.string
The branch to base changes on. Defaults to
main. Only used when repoUrl is provided.string
The Claude model to use. Defaults to
claude-opus-4-6.Response
Returns201 Created with the newly created session.
object
The created session object. See List Sessions for the full schema.
Example
This endpoint requires browser authentication (session cookie). The example below shows the request shape — to create sessions, use the Magnet dashboard or the API from an authenticated browser context.
cURL
curl -X POST "https://magnet.run/api/sessions" \
-H "Content-Type: application/json" \
-H "Cookie: __session=<your-session-token>" \
-d '{
"organizationId": "org_abc123",
"initialMessage": "Add input validation to the signup form. Email should be validated, password needs 8+ chars with at least one number.",
"repoUrl": "https://github.com/acme/web-app",
"baseBranch": "main"
}'
Response
{
"session": {
"id": "cm3abc123def",
"title": "Add input validation to signup form",
"status": "active",
"createdAt": "2026-02-11T10:00:00.000Z",
"updatedAt": "2026-02-11T10:00:00.000Z",
"model": "claude-opus-4-6",
"author": {
"id": "user_123",
"name": "Alice Chen"
},
"metadata": {
"repository": "acme/web-app"
},
"messageCount": 1,
"firstMessagePreview": "Add input validation to the signup form..."
}
}
Errors
| Status | Description |
|---|---|
400 | Invalid request body or API key used instead of browser session |
401 | Invalid or missing authentication |
403 | No access to the specified workspace |
500 | Server error |
Session creation requires browser authentication. If you need to create sessions programmatically, use the Magnet dashboard.