Connector API
Toscana protocol
If your system already runs agents with @tinkerlandai/toscana-client, it can run any Socialistic skill by changing its configuration alone. Point gatewayUrlat the skill and sign with your API key: the client’s own calls — createSession, dispatchRun, getRun, cancelRun, host tool calls, history and replay — land on the endpoints below, and runs are billed exactly as in Sessions & Runs.
createToscanaServerClient({
gatewayUrl: "https://connector.socialistic.ai/v1/toscana/<skill_slug>",
issuer: "<your API key's ID>",
serviceSecret: "<your API key, sk_live_…>",
// toscana-client >= 0.2.1: the browser streams from Toscana directly
streamDescriptorUrl:
"https://connector.socialistic.ai/v1/toscana/<skill_slug>/v1/api/sessions/{session_id}/stream-descriptor",
});Authentication
The client signs each call with an HS256 JWT made from issuer and serviceSecret. Set issuer to your key’s ID, shown under the key in Settings → API access, and serviceSecret to the key itself: Socialistic checks the signature with that key and runs everything as its owner. A service token (one without sub) may live at most 120 seconds, which is what the client mints. Calling these endpoints without the client, a plain Authorization: Bearer sk_live_… works too, as does an OAuth access token carrying session:run(OAuth tokens cannot sign JWTs: send them as the bearer).
A session JWT— the browser token the client signs with sessionSecret, whose subis a Toscana session id — is accepted only on replay_chunks and history, for that one session, and may live at most 24 hours. Set sessionSecret to the same key only if you rely on the fallback below.
Streaming to the browser
Set streamDescriptorUrl(toscana-client 0.2.1 or later): the client’s handlers then fetch the stream descriptor from Socialistic, and the browser streams straight from Toscana. Without it the client infers the descriptor itself, so the browser reads replay_chunksfrom Socialistic with a session JWT signed by your key. That works, with one extra hop, and the stream is cut every 300 seconds — the client reconnects with lastChunkId.
What differs from the Gateway
createSession:configmust be empty andephemeralfalse — the skill decides model, tools and billing. The response’sidis the Toscana session id every later call sends.- Every run draws your wallet — on your own skills too, where the creator margin comes back to you.
send_messageis non-streaming only, andturnEnv/maxCostUsdare refused with400 UNSUPPORTED_FIELD.getRunleaves out the provider cost fields andtraceId. In their place, once a run has ended and its charge is final,costis what your wallet was debited for it, in USD at the fixed rate of 700 credits per dollar (0when the run cost nothing), withcostSource: "socialistic"and the same amount in credits ascharge_credits. Your charge includes the creator’s share where there is one, never the upstream provider’s cost. Until the charge is final all three are absent, so a client reads the run as not settled yet. Reading a finished run settles it first if it hasn’t been, so you don’t wait on a background job; reading it again never charges twice.- Every session, run and tool call must be yours and on the skill in the URL; anything else answers 404, the same as a missing one.
Endpoints
POST/v1/toscana/:slug/v1/api/sessionssession:runAPI keyservice JWT
toscana-client createSession. Starts a session on the skill named in the URL (409 TOSCANA_RUNTIME_UNAVAILABLE, before anything is created, if the skill's new sessions are routed to the legacy runtime), billed exactly like POST /v1/sessions: the session always draws your wallet — on your own skills too, where the creator margin comes back to you. `config` must be empty and `ephemeral` false, otherwise 400 UNSUPPORTED_FIELD. `id` is the Toscana session id every later call sends; the snake_case fields are Socialistic extras the client ignores.
Request
| Field | Type | Description |
|---|---|---|
configoptional | object | Toscana SessionConfig. Must be empty: the skill in the URL decides model, tools and billing. |
sourceoptional | string | Accepted and ignored; sessions are recorded with source `connector`. |
ephemeraloptional | boolean | Must be false or absent. |
Response
| Field | Type | Description |
|---|---|---|
id | string | The Toscana session id — the `sessionId` every later call sends |
session_id | string (uuid) | Socialistic session id (the one /v1/sessions uses) |
streamoptional | object | Browser stream descriptor, as from the stream-descriptor endpoint |
stream.runtime | "toscana" | |
stream.token | string | |
stream.events_base_url | string | |
stream.stream_session_id | string |
POST/v1/toscana/:slug/v1/api/sessions/:sessionId/stream-descriptorsession:runAPI keyservice JWT
The browser stream descriptor for a session: a token the real Toscana Gateway accepts and its URL, so the browser streams from Toscana directly. Point toscana-client's streamDescriptorUrl (>= 0.2.1) here, with {session_id} in place of :sessionId, and its handlers hand the browser this descriptor. The token's labels are set by Socialistic; `labels` in the body is ignored.
Request
| Field | Type | Description |
|---|---|---|
labelsoptional | object | Accepted and ignored: the token's labels are set by Socialistic |
Response
| Field | Type | Description |
|---|---|---|
runtime | "toscana" | |
token | string | |
events_base_url | string | |
stream_session_id | string |
POST/v1/toscana/:slug/v1/stream/send_messagesession:runAPI keyservice JWT
toscana-client dispatchRun: sends a message and returns the run id once the run is accepted (same dispatch, billing and 409 RUN_PENDING as POST /v1/sessions/:sessionId/runs). `idempotencyKey` makes a re-send return the run the first send started. `busyPolicy: "BUSY_POLICY_ENQUEUE"` queues the run behind a busy session's work instead of answering 409 RUN_PENDING (`queued: true` in the answer). Only the non-streaming form is served (`stream` false or absent); `turnEnv` and `maxCostUsd` are not supported and answer 400 UNSUPPORTED_FIELD.
Request
| Field | Type | Description |
|---|---|---|
sessionId | string | Toscana session id from CreateSession |
query | string | |
attachmentsoptional | array<string (uri)> | Signed URLs the agent pulls into the turn |
turnEnvoptional | object | Not supported; must be empty |
streamoptional | boolean | Must be false or absent; read the run's events from replay_chunks |
idempotencyKeyoptional | string | |
maxCostUsdoptional | number | Not supported; must be 0 or absent |
busyPolicyoptional | "BUSY_POLICY_UNSPECIFIED" | "BUSY_POLICY_REJECT" | "BUSY_POLICY_ENQUEUE" | BUSY_POLICY_ENQUEUE queues the run behind a busy session's work |
Response
| Field | Type | Description |
|---|---|---|
runId | string | |
queuedoptional | boolean | True when the run waits in the session queue |
GET/v1/toscana/:slug/v1/api/runs/:runIdsession:runAPI keyservice JWT
toscana-client getRun: the Gateway's GetRun for one of your runs, without the provider cost fields (costBreakdown, providerName, providerGenerationId, maxCostUsd, budgetEnforced) or traceId. Once the run has ended and its charge is final, `cost` is what YOUR wallet was debited for it (USD at 700 credits per dollar; 0 when someone else paid) with `costSource: "socialistic"` and `charge_credits` in credits; until then all three are absent. Reading a finished run settles it first if it isn't yet, idempotently. A run that isn't yours answers 404 RUN_NOT_FOUND, like a missing one.
Request
No request body.
Response
| Field | Type | Description |
|---|---|---|
id | string | |
sessionId | string | |
status | string | queued | running | completed | failed | cancelled |
queryoptional | string | |
resultoptional | string | |
erroroptional | string | |
usageoptional | object | Token usage |
createdAtoptional | string | |
completedAtoptional | string | |
errorCodeoptional | string | |
errorOriginoptional | string | |
errorPhaseoptional | string | |
retryableoptional | boolean | |
retryAfterMsoptional | string | |
costoptional | number | What your wallet was debited for this run, in USD at the fixed credit rate (700 credits = $1); 0 when another party paid. Absent until the run is settled |
costSourceoptional | "socialistic" | `socialistic` once the run is settled and `cost` is final; absent before |
charge_creditsoptional | string | The same charge in platform credits (decimal string). A Socialistic extra the client ignores |
POST/v1/toscana/:slug/v1/api/runs/:runId/cancelsession:runAPI keyservice JWT
toscana-client cancelRun. Acknowledgement only: the run's cancelled chunk is the authoritative signal. Idempotent for your runs: cancelling one that has already ended acknowledges. A run id that isn't yours answers 404 RUN_NOT_FOUND, as the Gateway answers an unknown one.
Request
No request body.
Response
| Field | Type | Description |
|---|---|---|
acknowledged | boolean |
POST/v1/toscana/:slug/v1/api/runs/:runId/steersession:runAPI keyservice JWT
toscana-client steerRun: add text to one of your runs while it executes. Same rules and refusals as POST /v1/sessions/:sessionId/runs/:runId/steer; `idempotencyKey` is required.
Request
| Field | Type | Description |
|---|---|---|
runIdoptional | string | Must match the path when sent |
text | string | |
idempotencyKey | string |
Response
| Field | Type | Description |
|---|---|---|
runId | string | |
steerId | string |
POST/v1/toscana/:slug/v1/api/runs/:runId/tool_calls/:callId/claimsession:runAPI keyservice JWT
toscana-client claimToolCall: claim (or, with your claimToken, renew) a host tool call on one of your runs. Relayed to the Gateway; the answer is the Gateway's own.
Request
| Field | Type | Description |
|---|---|---|
runIdoptional | string | Must match the path when sent |
toolCallIdoptional | string | Must match the path when sent |
claimTokenoptional | string | The holder's token, to renew its lease |
Response
| Field | Type | Description |
|---|---|---|
state | string | CLAIM_STATE_GRANTED | _HELD | _ANSWERED | _GONE |
claimTokenoptional | string | |
leaseMsoptional | string |
POST/v1/toscana/:slug/v1/api/runs/:runId/submit_tool_resultsession:runAPI keyservice JWT
toscana-client submitToolResult: submit the outcome of a host tool call you hold. Relayed to the Gateway. 412 GATEWAY_REJECTED means the call is no longer pending — the outcome is lost; don't retry.
Request
| Field | Type | Description |
|---|---|---|
runIdoptional | string | Must match the path when sent |
toolCallId | string | |
claimToken | string | |
outcome | object | |
outcome.output | string |
Response
| Field | Type | Description |
|---|---|---|
accepted | boolean |
POST/v1/toscana/:slug/v1/stream/replay_chunkssession:runAPI keyservice JWTsession JWT
The session's chunk stream (server-sent events, raw Toscana chunk frames — toscana-client maps them), relayed from the Gateway. With `runId` it replays that run and closes at its terminal chunk; resume with `lastChunkId`. Answers cross-origin, so a browser whose descriptor was inferred locally can read it with a session JWT; the stream-descriptor endpoint avoids this hop. Cut at 300 s — reconnect with lastChunkId.
Request
| Field | Type | Description |
|---|---|---|
sessionId | string | |
lastChunkIdoptional | string | |
runIdoptional | string |
Response
No response body.
POST/v1/toscana/:slug/v1/stream/historysession:runAPI keyservice JWTsession JWT
The session's durable history as server-sent events (raw Toscana chunk frames), relayed from the Gateway; the stream closes after the backlog.
Request
| Field | Type | Description |
|---|---|---|
sessionId | string |
Response
No response body.