socialistic connector

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: config must be empty and ephemeralfalse — the skill decides model, tools and billing. The response’s id is 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_message is non-streaming only, and turnEnv / maxCostUsd are refused with 400 UNSUPPORTED_FIELD.
  • getRun leaves out the provider cost fields and traceId. In their place, once a run has ended and its charge is final, cost is what your wallet was debited for it, in USD at the fixed rate of 700 credits per dollar (0 when the run cost nothing), with costSource: "socialistic" and the same amount in credits as charge_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
FieldTypeDescription
configoptionalobjectToscana SessionConfig. Must be empty: the skill in the URL decides model, tools and billing.
sourceoptionalstringAccepted and ignored; sessions are recorded with source `connector`.
ephemeraloptionalbooleanMust be false or absent.
Response
FieldTypeDescription
idstringThe Toscana session id — the `sessionId` every later call sends
session_idstring (uuid)Socialistic session id (the one /v1/sessions uses)
streamoptionalobjectBrowser stream descriptor, as from the stream-descriptor endpoint
stream.runtime"toscana"
stream.tokenstring
stream.events_base_urlstring
stream.stream_session_idstring
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
FieldTypeDescription
labelsoptionalobjectAccepted and ignored: the token's labels are set by Socialistic
Response
FieldTypeDescription
runtime"toscana"
tokenstring
events_base_urlstring
stream_session_idstring
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
FieldTypeDescription
sessionIdstringToscana session id from CreateSession
querystring
attachmentsoptionalarray<string (uri)>Signed URLs the agent pulls into the turn
turnEnvoptionalobjectNot supported; must be empty
streamoptionalbooleanMust be false or absent; read the run's events from replay_chunks
idempotencyKeyoptionalstring
maxCostUsdoptionalnumberNot 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
FieldTypeDescription
runIdstring
queuedoptionalbooleanTrue 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
FieldTypeDescription
idstring
sessionIdstring
statusstringqueued | running | completed | failed | cancelled
queryoptionalstring
resultoptionalstring
erroroptionalstring
usageoptionalobjectToken usage
createdAtoptionalstring
completedAtoptionalstring
errorCodeoptionalstring
errorOriginoptionalstring
errorPhaseoptionalstring
retryableoptionalboolean
retryAfterMsoptionalstring
costoptionalnumberWhat 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_creditsoptionalstringThe 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
FieldTypeDescription
acknowledgedboolean
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
FieldTypeDescription
runIdoptionalstringMust match the path when sent
textstring
idempotencyKeystring
Response
FieldTypeDescription
runIdstring
steerIdstring
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
FieldTypeDescription
runIdoptionalstringMust match the path when sent
toolCallIdoptionalstringMust match the path when sent
claimTokenoptionalstringThe holder's token, to renew its lease
Response
FieldTypeDescription
statestringCLAIM_STATE_GRANTED | _HELD | _ANSWERED | _GONE
claimTokenoptionalstring
leaseMsoptionalstring
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
FieldTypeDescription
runIdoptionalstringMust match the path when sent
toolCallIdstring
claimTokenstring
outcomeobject
outcome.outputstring
Response
FieldTypeDescription
acceptedboolean
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
FieldTypeDescription
sessionIdstring
lastChunkIdoptionalstring
runIdoptionalstring
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
FieldTypeDescription
sessionIdstring
Response

No response body.