Skip to main content

API

Smartloop Studio is installed, or you have just installed the command line tools using curl. The agent exposes an API that you can use to extend the tool for your own workflow.

The chat completion endpoint is OpenAI-compatible, making it easy to build applications on top of it or migrate existing ones with minimal effort.

API Endpoint

First grab the base URL by copying and pasting the following command to your terminal:

slp status

This will return a table listing model size, context, project, etc. for the device:

PropertyValue
Serverhttp://127.0.0.1:38540
PID40372
QuantizationQ4_K_M
Context window4096
Flash attentionFalse
Model size2.3 GB
Memory usage15%
GPUApple Silicon (MPS)
Active projectgeneral_chat (id=533338cf-5980-4f6a-aeea-02fe9fa92999)

You can explore the interactive API documentation at http://127.0.0.1:38540/docs.

info

If the agent is not already running, start it with:

slp agent start

The API follows the OpenAI Chat Completions specification, so any client or SDK that supports OpenAI will work out of the box.

Quick Start (Python)

Install the OpenAI Python SDK:

pip install openai

Send your first chat completion request:

from openai import OpenAI

client = OpenAI(
base_url="http://127.0.0.1:38540/v1",
api_key="not-needed",
)

response = client.chat.completions.create(
model="slp-orchestra-mini",
messages=[
{"role": "user", "content": "What is the capital of France?"}
],
)

print(response.choices[0].message.content)

Quick Start (JavaScript)

Install the OpenAI Node.js SDK:

npm install openai
import OpenAI from "openai";

const client = new OpenAI({
baseURL: "http://127.0.0.1:38540/v1",
apiKey: "not-needed",
});

const response = await client.chat.completions.create({
model: "slp-orchestra-mini",
messages: [
{ role: "user", content: "What is the capital of France?" },
],
});

console.log(response.choices[0].message.content);

Quick Start (cURL)

curl http://127.0.0.1:38540/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "slp-orchestra-mini",
"messages": [
{"role": "user", "content": "What is the capital of France?"}
]
}'

Message Roles

RoleDescription
systemSets the behavior and context for the assistant
userThe end user's message
assistantPrevious assistant responses (for multi-turn conversations)

Response Format

{
"id": "chatcmpl-...",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
]
}

Access the response content:

response.choices[0].message.content

Multi-turn Conversations

To maintain context across messages, include the conversation history:

response = client.chat.completions.create(
model="slp-orchestra-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "My name is Alice."},
{"role": "assistant", "content": "Hello Alice! How can I help you today?"},
{"role": "user", "content": "What's my name?"},
],
)