Skip to main content

Agent API

GeniSpace provides two ways to invoke an agent, plus an OpenAI-compatible relay for existing OpenAI clients:

  1. Multimodal Chat (/chat) — GeniSpace-native protocol using a contents[] array, with Server-Sent Events (SSE) streaming by default. Supports text, images, audio, and files.
  2. Agent Execution (/execute) — Structured protocol with an inputs object and agent-specific feature toggles (memory, knowledge-base context, web search), returning a compact result.
  3. OpenAI-Compatible Relay (/models/v1/*) — If you need to reuse an existing OpenAI SDK, point it at the relay described in the API Overview. The agent chat endpoint itself is not OpenAI-messages-compatible.

All agent invocation endpoints are gated by agent access control: callers must have access to the target agent.

Multimodal Chat

Endpoint

POST /api/agents/{agentId}/chat

Description

The native GeniSpace chat protocol. It accepts a multimodal contents[] array and, by default, streams the response back as Server-Sent Events (text/event-stream). This endpoint does not use the OpenAI messages format.

Request Parameters

ParameterTypeRequiredDescription
contentsarrayMultimodal content array (must be non-empty). Each item has a type of text, image_url, audio, or file.
session_idstringConversation session ID for multi-turn context
streambooleanWhether to stream results via SSE. Defaults to true.
settingsobjectModel parameter settings (see below)

contents item shape

{ "type": "text", "text": "Message text" }
{ "type": "image_url", "image_url": { "url": "https://...", "detail": "auto" } }
{ "type": "audio", "audio_url": { "url": "https://..." } }
{ "type": "file", "file_info": { /* file metadata */ } }

The image_url.url and audio_url.url values accept both HTTP(S) URLs and data: base64 URIs.

settings parameters

FieldTypeRange / DefaultDescription
temperaturenumber0–2Controls output randomness
max_tokensinteger≥ 1Maximum output tokens
top_pnumber0–1Nucleus sampling
frequency_penaltynumberFrequency penalty
presence_penaltynumberPresence penalty

Request Examples

Streaming Request (default)

curl -X POST "https://api.genispace.ai/api/agents/550e8400-e29b-41d4-a716-446655440000/chat" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{ "type": "text", "text": "Please help me write a market analysis report" }
],
"settings": { "temperature": 0.7, "max_tokens": 2000 }
}'

Multimodal Request (text + image)

curl -X POST "https://api.genispace.ai/api/agents/550e8400-e29b-41d4-a716-446655440000/chat" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{ "type": "text", "text": "Describe this chart" },
{ "type": "image_url", "image_url": { "url": "https://example.com/chart.png" } }
],
"session_id": "ses_1234567890123_abcdef",
"stream": false
}'

Response Format

When stream is true (the default), the response has Content-Type: text/event-stream and emits SSE data: lines as the agent produces output, for example:

data: {"event": "session.started", "session_id": "ses_1234567890123_abcdef"}

data: {"event": "response.completed", "session_id": "ses_1234567890123_abcdef", "tokens_used": 620, "execution_time": 31017}

When stream is false, the response is a single JSON body.

Agent Execution

Endpoint

POST /api/agents/{agentId}/execute

Description

GeniSpace's structured execution protocol. It accepts an inputs object and returns a compact result with the answer, timing, and token usage. Use this when you want a single structured response and optional agent features such as memory, knowledge-base context, and web search.

Request Parameters

ParameterTypeRequiredDescription
inputsobjectAgent input parameters and feature toggles (see below)
settingsobjectModel parameter settings
streambooleanWhether to stream results via SSE. Defaults to false.

inputs parameters

The inputs object accepts the following recognized fields, plus any additional custom variables your agent's prompt template expects:

FieldTypeRequiredDescription
querystringUser query content
session_idstringConversation session ID for multi-turn context
memorybooleanEnable memory, default false
contextbooleanEnable knowledge-base context retrieval, default false
internetbooleanEnable internet search, default false
imagesstring[]Image URLs or data: base64 URIs
audiosstring[]Audio URLs or data: base64 URIs
{
"inputs": {
"query": "User query content",
"session_id": "ses_1234567890123_abcdef",
"memory": true,
"context": true,
"internet": false,
"images": ["https://example.com/image1.jpg"]
}
}

settings parameters

FieldTypeRangeDescription
temperaturenumber0–1Controls output randomness
maxTokensinteger≥ 1Maximum output tokens
top_pnumber0–1Nucleus sampling
presence_penaltynumberPresence penalty
frequency_penaltynumberFrequency penalty
{
"settings": {
"temperature": 0.7,
"maxTokens": 2000,
"top_p": 1.0,
"presence_penalty": 0,
"frequency_penalty": 0
}
}

Request Examples

Basic Query

curl -X POST "https://api.genispace.ai/api/agents/550e8400-e29b-41d4-a716-446655440000/execute" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"inputs": {
"query": "Hello",
"memory": true
},
"settings": {
"temperature": 0.7,
"maxTokens": 2000
}
}'

Enable Agent Features

curl -X POST "https://api.genispace.ai/api/agents/550e8400-e29b-41d4-a716-446655440000/execute" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"inputs": {
"query": "Help me analyze customer satisfaction data",
"memory": true,
"context": true,
"internet": true
},
"settings": {
"temperature": 0.3,
"maxTokens": 1500
}
}'

Response Format

Success Response

{
"answer": "Hello! I'm happy to help...",
"agent_id": "550e8400-e29b-41d4-a716-446655440000",
"execution_time": 2.35,
"token_usage": {
"prompt_tokens": 168,
"completion_tokens": 85,
"total_tokens": 253,
"cost": 0.012
}
}

Response Field Descriptions

FieldTypeDescription
answerstringThe response content generated by the agent
agent_idstringID of the executed agent
execution_timenumberExecution time (seconds)
token_usageobjectToken usage statistics
token_usage.prompt_tokensintegerInput token count
token_usage.completion_tokensintegerOutput token count
token_usage.total_tokensintegerTotal token count
token_usage.costnumberBilled cost for the execution

When stream is true, the response is delivered as SSE (text/event-stream) instead of a single JSON body.

Agent Access Control

When creating an agent (POST /api/agents), the following fields are required: name, model, and systemPrompt. You can also control who within the space may invoke the agent:

FieldTypeDescription
accessScopestringSPACE (all space members) or RESTRICTED (only listed users)
allowedUserIdsstring[]User IDs allowed to access a RESTRICTED agent

When listing agents (GET /api/agents), pass accessibleOnly=true to return only the agents the caller can access. All invocation endpoints enforce this access control.

Error Handling

All agent endpoints use the standard flat error envelope:

{
"success": false,
"message": "Resource not found",
"code": "NOT_FOUND"
}

Common Error Codes

Error CodeHTTP StatusDescription
VALIDATION_ERROR400Invalid request parameters
UNAUTHORIZED401Missing or invalid credentials
FORBIDDEN403No access to the requested agent
NOT_FOUND404Agent does not exist
INSUFFICIENT_TOKENS402Token balance depleted
SERVER_ERROR500Internal server error

See Error Handling for the complete list.

Best Practices

Choosing the Right Protocol

  • Use Chat (/chat) when:

    • You want streaming responses (SSE)
    • You need multimodal inputs (images, audio, files)
    • You are building an interactive conversational experience
  • Use Execute (/execute) when:

    • You want a single structured result with token usage and timing
    • You want to toggle agent features (memory, knowledge-base context, web search)
    • You are passing custom prompt-template variables
  • Use the OpenAI relay (/models/v1/*) when:

    • You need to reuse an existing OpenAI SDK or codebase

Performance Optimization

  • Selectively enable features based on requirements: memory, context, internet
  • Set maxTokens / max_tokens appropriately to control response length and cost
  • Adjust temperature based on task complexity

Security Considerations

  • Always validate user input to prevent injection attacks
  • Restrict agent access with accessScope / allowedUserIds in production
  • Apply appropriate data masking for sensitive data

SDK Support

JavaScript SDK

The official GeniSpace JavaScript SDK supports agent chat and execution. See Developer Resources for details.

import GeniSpace from 'genispace';

const client = new GeniSpace({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.genispace.ai/api'
});

// Multimodal chat (GeniSpace-native contents[])
const chatResponse = await client.agents.chat('550e8400-e29b-41d4-a716-446655440000', {
contents: [{ type: 'text', text: 'Analyze sales data' }],
settings: { temperature: 0.7 }
});

// Agent execution (structured inputs)
const execResponse = await client.agents.execute('550e8400-e29b-41d4-a716-446655440000', {
inputs: {
query: 'Analyze sales data',
memory: true,
context: true,
internet: false
},
settings: {
temperature: 0.7,
maxTokens: 2000
}
});