Start a new agent session and post the first user message.
POST /rest/v1/sessions
Creates a new session for the authenticated workspace, posts the initial user message, and dispatches it to the agent. The response includes a pre-built _links.final_message.href URL — poll it to receive the assistant’s reply.
const res = await fetch("https://api.blocks.team/rest/v1/sessions", { method: "POST", headers: { Authorization: `ApiKey ${process.env.BLOCKS_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ agent_name: "claude", message: "Say hello and tell me a one-sentence fun fact about octopuses.", }),});const session = await res.json();
import os, requestssession = requests.post( "https://api.blocks.team/rest/v1/sessions", headers={ "Authorization": f"ApiKey {os.environ['BLOCKS_API_KEY']}", "Content-Type": "application/json", }, json={ "agent_name": "claude", "message": "Say hello and tell me a one-sentence fun fact about octopuses.", },).json()
curl -X POST https://api.blocks.team/rest/v1/sessions \ -H "Authorization: ApiKey $BLOCKS_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "agent_name": "claude", "message": "Say hello and tell me a one-sentence fun fact about octopuses." }'
import java.net.URI;import java.net.http.*;HttpResponse<String> res = HttpClient.newHttpClient().send( HttpRequest.newBuilder(URI.create("https://api.blocks.team/rest/v1/sessions")) .header("Authorization", "ApiKey " + System.getenv("BLOCKS_API_KEY")) .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString( "{\"agent_name\":\"claude\",\"message\":\"Say hello and tell me a one-sentence fun fact about octopuses.\"}")) .build(), HttpResponse.BodyHandlers.ofString());
require "net/http"require "json"session = JSON.parse(Net::HTTP.post( URI("https://api.blocks.team/rest/v1/sessions"), JSON.generate({ agent_name: "claude", message: "Say hello and tell me a one-sentence fun fact about octopuses.", }), { "Authorization" => "ApiKey #{ENV['BLOCKS_API_KEY']}", "Content-Type" => "application/json", },).body)
body, _ := json.Marshal(map[string]string{ "agent_name": "claude", "message": "Say hello and tell me a one-sentence fun fact about octopuses.",})req, _ := http.NewRequest("POST", "https://api.blocks.team/rest/v1/sessions", bytes.NewReader(body))req.Header.Set("Authorization", "ApiKey "+os.Getenv("BLOCKS_API_KEY"))req.Header.Set("Content-Type", "application/json")res, _ := http.DefaultClient.Do(req)