Create Session
curl --request POST \
--url https://api.nexusgpt.io/api/public/thread \
--header 'Content-Type: application/json' \
--header 'api-key: <api-key>' \
--data '
{
"message": "<string>"
}
'import requests
url = "https://api.nexusgpt.io/api/public/thread"
payload = { "message": "<string>" }
headers = {
"api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({message: '<string>'})
};
fetch('https://api.nexusgpt.io/api/public/thread', 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.nexusgpt.io/api/public/thread",
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([
'message' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"api-key: <api-key>"
],
]);
$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.nexusgpt.io/api/public/thread"
payload := strings.NewReader("{\n \"message\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("api-key", "<api-key>")
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.nexusgpt.io/api/public/thread")
.header("api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"message\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.nexusgpt.io/api/public/thread")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"message\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "550e8400-e29b-41d4-a716-446655440000",
"createdAt": "2024-01-20T10:30:00Z"
}
Endpoints
Create Session
Create a new chat session with your AI agent
POST
/
api
/
public
/
thread
Create Session
curl --request POST \
--url https://api.nexusgpt.io/api/public/thread \
--header 'Content-Type: application/json' \
--header 'api-key: <api-key>' \
--data '
{
"message": "<string>"
}
'import requests
url = "https://api.nexusgpt.io/api/public/thread"
payload = { "message": "<string>" }
headers = {
"api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({message: '<string>'})
};
fetch('https://api.nexusgpt.io/api/public/thread', 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.nexusgpt.io/api/public/thread",
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([
'message' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"api-key: <api-key>"
],
]);
$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.nexusgpt.io/api/public/thread"
payload := strings.NewReader("{\n \"message\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("api-key", "<api-key>")
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.nexusgpt.io/api/public/thread")
.header("api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"message\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.nexusgpt.io/api/public/thread")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"message\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "550e8400-e29b-41d4-a716-446655440000",
"createdAt": "2024-01-20T10:30:00Z"
}
Create Session
Creates a new chat session with your configured AI agent. This establishes a conversation thread that maintains context across multiple messages.Endpoint
POST https://api.nexusgpt.io/api/public/thread
Authentication
string
required
Your Nexus API key for authentication
Request Body
string
Optional initial message to send to the agent when creating the session. This can help set the context for the conversation.
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"createdAt": "2024-01-20T10:30:00Z"
}
Response Fields
string
required
Unique identifier for the created session. You’ll need this ID to send messages and retrieve conversation history.
string
required
ISO 8601 timestamp indicating when the session was created
Example Usage
curl -X POST https://api.nexusgpt.io/api/public/thread \
-H "Content-Type: application/json" \
-H "api-key: YOUR_API_KEY"
const axios = require('axios');
async function createSession() {
try {
const response = await axios.post(
'https://api.nexusgpt.io/api/public/thread',
{},
{
headers: {
'Content-Type': 'application/json',
'api-key': process.env.NEXUS_API_KEY
}
}
);
console.log('Session created:', response.data.id);
return response.data;
} catch (error) {
console.error('Error creating session:', error.response?.data);
throw error;
}
}
// Create session
const session = await createSession();
// Now send your first message
await sendMessage(session.id, 'Hello, I need help with my account');
import os
import requests
def create_session(initial_message=None):
"""Create a new chat session"""
url = "https://api.nexusgpt.io/api/public/thread"
headers = {
"Content-Type": "application/json",
"api-key": os.environ.get("NEXUS_API_KEY")
}
data = {}
if initial_message:
data["message"] = initial_message
try:
response = requests.post(url, json=data, headers=headers)
response.raise_for_status()
session = response.json()
print(f"Session created: {session['id']}")
return session
except requests.exceptions.RequestException as e:
print(f"Error creating session: {e}")
if hasattr(e, 'response'):
print(f"Response: {e.response.text}")
raise
# Create session with initial message
session = create_session("Hello, I need help with my account")
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
type CreateSessionRequest struct {
Message string `json:"message,omitempty"`
}
type SessionResponse struct {
ID string `json:"id"`
CreatedAt string `json:"createdAt"`
}
func createSession(initialMessage string) (*SessionResponse, error) {
url := "https://api.nexusgpt.io/api/public/thread"
requestBody := CreateSessionRequest{}
if initialMessage != "" {
requestBody.Message = initialMessage
}
jsonData, err := json.Marshal(requestBody)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("api-key", os.Getenv("NEXUS_API_KEY"))
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("API error: %s", string(body))
}
var session SessionResponse
if err := json.Unmarshal(body, &session); err != nil {
return nil, err
}
fmt.Printf("Session created: %s\n", session.ID)
return &session, nil
}
Common Use Cases
1. Customer Support Bot
// Create a session for customer support
const session = await createSession(
"Hello, I'm having trouble with my recent order #12345"
);
2. Product Assistant
// Create a session for product inquiries
const session = await createSession(
"I'm looking for recommendations on running shoes for marathons"
);
3. Technical Support
// Create a session for technical assistance
const session = await createSession(
"My application is showing an error when I try to export data"
);
Error Responses
{
"statusCode": 401,
"message": "Invalid API key",
"error": "Unauthorized"
}
{
"statusCode": 400,
"message": "Invalid request body",
"error": "Bad Request"
}
{
"statusCode": 429,
"message": "Rate limit exceeded",
"error": "Too Many Requests"
}
{
"statusCode": 500,
"message": "An unexpected error occurred",
"error": "Internal Server Error"
}
Best Practices
Session Lifecycle
Session Lifecycle
- Sessions remain active for 24 hours of inactivity
- Reuse sessions for continued conversations
- Create new sessions for unrelated topics
- Store session IDs securely in your application
Initial Messages
Initial Messages
- Use initial messages to provide context
- Include relevant details upfront
- Set clear expectations for the conversation
- Avoid sensitive information in initial messages
Error Handling
Error Handling
- Always check for error responses
- Implement retry logic for transient failures
- Log session IDs for debugging
- Have fallback behavior for session creation failures
Related Endpoints
- Send Message - Send messages to an existing session
- Get Session - Retrieve session information
- List Messages - Get conversation history