API Reference

The Stratipy REST API lets you register apps, manage users, deploy AI strategy instances, and run conversations programmatically.

Base URL

https://api.stratipy.com

Authentication

Stratipy uses two types of API keys, passed via the X-api-key header:

  • sk_... — Secret key for server-side operations (user management, billing, deployments)
  • pk_... — Publishable key for browser-side use (conversations, streaming). Origin validated against your registered host.
curl https://api.stratipy.com/strategies \
  -H "X-api-key: sk_your_key_here"

Endpoints

POST/app

Register a new Stratipy app. Returns the app ID and secret key. Each app gets its own isolated database.

Request Body

{
  "name": "My AI App"
}

Response

{
  "id": "01JHXYZ...",
  "name": "my-ai-app",
  "secretKey": "sk_..."
}
POST/userRequires API key

Create a user within your app. Returns a publishable key for browser-side authentication.

Request Body

{
  "email": "user@example.com",
  "name": "Jane Doe"
}

Response

{
  "id": "01JHXYZ...",
  "email": "user@example.com",
  "publishableKey": "pk_..."
}
GET/strategiesRequires API key

List all available AI strategies with metadata, pricing, and configuration props.

Response

[
  {
    "metadata": {
      "id": "chat",
      "name": "Chat",
      "description": "Open-ended conversation with an AI assistant.",
      "category": "conversation",
      "tags": ["general", "open-ended"]
    },
    "pricing": { "creditsPerTurn": 1, "setupCredits": 0 },
    "available": true
  },
  {
    "metadata": {
      "id": "data-analysis",
      "name": "Data Analysis",
      "description": "Upload a CSV file and ask questions about your data.",
      "category": "analysis",
      "tags": ["csv", "data", "upload"]
    },
    "pricing": { "creditsPerTurn": 2, "setupCredits": 1 },
    "available": true
  }
]
POST/strategies/instancesRequires API key

Deploy a strategy instance to a specific host domain. The instance can be configured and activated from the dashboard.

Request Body

{
  "templateId": "chat",
  "host": "example.com"
}

Response

{
  "id": "01JHXYZ...",
  "templateId": "chat",
  "host": "example.com",
  "status": "ACTIVE"
}
POST/strategies/instances/{id}/conversationsRequires API key

Start a new conversation against an active strategy instance. Works with both publishable and secret keys.

Request Body

{
  "config": {}
}

Response

{
  "conversationId": "01JHXYZ...",
  "instanceId": "01JHXYZ...",
  "strategyId": "chat"
}
POST/strategies/instances/{id}/conversations/{conversationId}Requires API key

Send a message in a conversation. The AI response streams via SSE on the events endpoint. Attachments are optional.

Request Body

{
  "text": "Hello!",
  "attachments": [
    {
      "name": "report.pdf",
      "url": "https://...",
      "size": 102400,
      "contentType": "application/pdf"
    }
  ]
}

Response

200 OK (empty body)
GET/strategies/instances/{id}/conversations/{conversationId}/eventsRequires API key

Stream AI responses via Server-Sent Events. Connect before sending a message. Authenticated via the X-api-key header (use fetch + ReadableStream on the browser; the SDK handles this for you).

Response

data: {"text":"AI response chunk...","conversationId":"01JHXYZ..."}

data: {"text":"More text...","conversationId":"01JHXYZ..."}

event: finish
data: {}
GET/strategies/instances/{id}/conversations/{conversationId}/messagesRequires API key

Get the full message history for a conversation. Useful for rehydrating state or server-side logging.

Response

[
  {
    "id": "01JHXYZ...",
    "conversationId": "01JHXYZ...",
    "role": "user",
    "content": "Hello!",
    "createdAt": "2026-01-15T10:30:00Z"
  },
  {
    "id": "01JHXYZ...",
    "conversationId": "01JHXYZ...",
    "role": "assistant",
    "content": "Hi! How can I help?",
    "createdAt": "2026-01-15T10:30:05Z"
  }
]
POST/strategies/instances/{id}/conversations/{conversationId}/cancelRequires API key

Cancel a conversation in progress. Stops AI processing and saves credits.

Response

200 OK (empty body)
GET/strategies/instances/{id}/conversationsRequires API key

List all conversations for an instance. Returns conversation metadata including status and timestamps.

Response

[
  {
    "id": "01JHXYZ...",
    "instanceId": "01JHXYZ...",
    "channel": "web",
    "status": "OPEN",
    "createdAt": "2026-01-15T10:30:00Z",
    "updatedAt": "2026-01-15T10:35:00Z"
  }
]
POST/strategies/instances/{id}/webhooksRequires API key

Create a webhook to receive notifications for conversation events. Secret key required. The webhook secret is shown once in the response — use it to verify signatures via the X-Webhook-Signature header.

Request Body

{
  "url": "https://your-backend.com/webhook",
  "events": [
    "conversation_started",
    "conversation_finished",
    "conversation_error"
  ]
}

Response

{
  "id": "01JHXYZ...",
  "url": "https://your-backend.com/webhook",
  "events": ["conversation_started", ...],
  "secret": "whsec_...",
  "active": true
}

React SDK

The easiest way to integrate is with @stratipy/react.

npm install @stratipy/react

Drop-in Chat Widget

Add a floating chat widget with one component — no custom UI needed:

import { StratipyChat } from "@stratipy/react"

function App() {
  return (
    <StratipyChat.Default
      instanceId="your_instance_id"
      apiKey="pk_your_key"
      title="Support"
      position="bottom-right"
    />
  )
}

StratipyChat.Default renders a fully styled floating chat panel with auto-scrolling, keyboard shortcuts, and streaming indicators. Customize with title, placeholder, position, and defaultOpen props.

Headless Component

Use the render-prop component for full control over the UI:

import { StratipyChat } from "@stratipy/react"

function Chat() {
  return (
    <StratipyChat
      instanceId="your_instance_id"
      apiKey="pk_your_key"
    >
      {({ messages, send, streaming, inputProps, submitInput, scrollRef }) => (
        <div>
          <div ref={scrollRef}>
            {messages.map(msg => (
              <div key={msg.id}>{msg.text}</div>
            ))}
          </div>
          <textarea {...inputProps} />
          <button onClick={submitInput}>Send</button>
        </div>
      )}
    </StratipyChat>
  )
}

The render prop receives all conversation state plus helpers: auto-scrolling, scroll-up detection, textarea auto-resize, and Enter-to-send keyboard handling.

Hooks

For maximum flexibility, use the hooks directly:

import { useStratipy, useChatHelpers } from "@stratipy/react"

function Chat() {
  const chat = useStratipy({
    instanceId: "your_instance_id",
    apiKey: "pk_your_key",
  })
  const { scrollRef, inputProps, submitInput } = useChatHelpers(chat)

  // Build any UI you want
}

useStratipy manages conversation state and returns messages, send, streaming, error, reset, and cancel. useChatHelpers adds auto-scrolling, textarea management, and keyboard handling.

Framework-Agnostic Core

Not using React? Import from @stratipy/react/core to use with Vue, Svelte, or vanilla JS.

ChatSession

A stateful class that manages the full conversation lifecycle with a pub-sub interface:

import { ChatSession } from "@stratipy/react/core"

const session = new ChatSession({
  instanceId: "your_instance_id",
  apiKey: "pk_your_key",
})

// Subscribe to state changes
session.subscribe((state) => {
  console.log(state.messages, state.streaming)
})

// Send a message
await session.send("Hello!")

// Reset or cancel
session.reset()
await session.cancel()

// Clean up when done
session.destroy()

ChatSession handles conversation creation, SSE streaming with reconnection, and state management. Listeners receive the full state on every change.

Low-level Functions

For full control over each step:

import {
  createConversation,
  sendMessage,
  cancelConversation,
} from "@stratipy/react/core"

const opts = {
  instanceId: "your_instance_id",
  apiKey: "pk_your_key",
}

// 1. Create a conversation
const { conversationId } = await createConversation(opts)

// 2. Send a message and stream the response
const handle = sendMessage(opts, conversationId, "Hello!", {
  onMessage: (text) => console.log(text),
  onFinish: () => console.log("Done"),
  onError: (err) => console.error(err.message),
})

// 3. Cancel mid-turn if needed
handle.cancel()

// 4. End the conversation entirely
await cancelConversation(opts, conversationId)

Each sendMessage opens a short-lived SSE stream for that turn and closes on completion — no long-lived connections.

API Documentation — Stratipy