> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://devin.ferndocs.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://devin.ferndocs.com/_mcp/server.

# Create a new session

POST https://api.devin.ai/v1/sessions
Content-Type: application/json

Create a new Devin session with the specified prompt and configuration options.

Reference: https://devin.ferndocs.com/api-reference/v-1/create-session

## Authentication

- `Authorization` header (bearer token, required) — Personal API Key (apk_user_*) or Service API Key (apk_*)

## Request

### Body (application/json)

This endpoint expects a CreateSessionParams.

- `prompt` (string, required)
- `idempotent` (boolean, optional, default: false)
- `knowledge_ids` (list of string, optional, nullable) — List of knowledge IDs to use. If None, use all knowledge. If empty list, use no knowledge.
- `max_acu_limit` (integer, optional, nullable) — Maximum ACU limit, must be positive
- `playbook_id` (string, optional, nullable)
- `secret_ids` (list of string, optional, nullable) — List of secret IDs to use. If None, use all secrets. If empty list, use no secrets.
- `session_secrets` (list of SessionSecretInput, optional, nullable) — List of session-specific secrets to use. These secrets are only available in this session and are not stored in organization secrets.
- `snapshot_id` (string, optional, nullable)
- `structured_output_schema` (map from string to any, optional, nullable) — JSON Schema (Draft 7) for validating structured output. Max 64KB. Must be self-contained (no external $ref).
- `tags` (list of string, optional, nullable) — List of tags to add to the session.
- `title` (string, optional, nullable) — Custom title for the session. If None, a title will be generated automatically.
- `unlisted` (boolean, optional, default: false)

## Response

### 200

Successful Response

- `session_id` (string, required)
- `url` (string, required)
- `is_new_session` (boolean, optional, nullable)

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### SessionSecretInput

Input model for a session secret provided via API.

- `key` (string, required)
- `value` (string, required)
- `sensitive` (boolean, optional, default: true)

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)

### ValidationErrorLocItems

## Examples

**Request**

```json
{
  "prompt": "Explain the principles of quantum computing in simple terms."
}
```

**Response**

```json
{
  "session_id": "a1b2c3d4-e5f6-7890-ab12-cd34ef567890",
  "url": "https://app.devin.ai/sessions/a1b2c3d4-e5f6-7890-ab12-cd34ef567890",
  "is_new_session": true
}
```

**SDK Code**

```python
import requests

url = "https://api.devin.ai/v1/sessions"

payload = { "prompt": "Explain the principles of quantum computing in simple terms." }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.devin.ai/v1/sessions';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"prompt":"Explain the principles of quantum computing in simple terms."}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.devin.ai/v1/sessions"

	payload := strings.NewReader("{\n  \"prompt\": \"Explain the principles of quantum computing in simple terms.\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.devin.ai/v1/sessions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"prompt\": \"Explain the principles of quantum computing in simple terms.\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.devin.ai/v1/sessions")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"prompt\": \"Explain the principles of quantum computing in simple terms.\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.devin.ai/v1/sessions', [
  'body' => '{
  "prompt": "Explain the principles of quantum computing in simple terms."
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.devin.ai/v1/sessions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"prompt\": \"Explain the principles of quantum computing in simple terms.\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["prompt": "Explain the principles of quantum computing in simple terms."] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.devin.ai/v1/sessions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```