RPC API
Path-based HTTP JSON under /api/rpc/ — authenticate once, then call {{model}}/{{method}} with an API key or session.
Source: sumeru/core/server/web/rpc_json.go, sumeru/core/server/api/rpc_body.go, sumeru/core/server/api/dispatch.go
Integrators use path-based HTTP JSON (not a flat POST /api/rpc body with model/method/args). The SWC browser client uses the same prefix with session cookies and CSRF.
Ops probes (outside RPC): GET /api/health (liveness), GET /api/ready (database) — plain JSON, not the RPC envelope below.
Quick start
Prerequisites
- Running Sumeru instance (HTTPS in production; TLS enables HTTP/2 on the Go listener when configured).
- Server
db_name(e.g.sumeru) and a company id or name forX-Sumeru-Tenant(often1). - A user allowed on that company with password sign-in enabled.
Replace https://erp.example.com, database name, tenant, and credentials in the examples below.
Step 1 — Authenticate
POST /api/rpc/auth.login with database and tenant headers. Do not send Authorization. On success, store data.api_key (sk_…) — shown once.
BASE="https://erp.example.com"DB="sumeru"TENANT="1"curl -sS -X POST "$BASE/api/rpc/auth.login" \ -H "Content-Type: application/json" \ -H "X-Sumeru-Database: $DB" \ -H "X-Sumeru-Tenant: $TENANT" \ -d '{ "context": { "lang": "en_US" }, "login": "integrator@example.com", "password": "YOUR_PASSWORD" }'Success returns data.api_key and data.session_id. Store the API key in a secret manager.
Step 2 — Call a model method
API_KEY="sk_paste_from_login_response"curl -sS -X POST "$BASE/api/rpc/core.partner/search_read" \ -H "Content-Type: application/json" \ -H "X-Sumeru-Database: $DB" \ -H "X-Sumeru-Tenant: $TENANT" \ -H "Authorization: Bearer $API_KEY" \ -d '{ "domain": [["active", "=", true]], "fields": ["name", "email"], "limit": 5 }'Check success": true and read data. Errors use the same envelope — see Response envelope.
Step 3 — Optional health check
curl -sS "$BASE/api/rpc/core.partner/health" \ -H "X-Sumeru-Database: $DB" \ -H "X-Sumeru-Tenant: $TENANT" \ -H "Authorization: Bearer $API_KEY"Confirms the model is registered and lists public RPC method names. Details under Model health.
Conventions
Required headers
| Header | When | Rule |
|---|---|---|
X-Sumeru-Database | All /api/rpc/ calls | Must match server db_name in config |
X-Sumeru-Tenant | All /api/rpc/ calls | Active company id (e.g. 1) or exact core.company name |
Content-Type | POST bodies | application/json |
Authorization | Model RPC, health GET | Bearer sk_… or X-API-Key: sk_… |
Authorization | auth.login | Must be absent (400 if Bearer or session is treated as pre-auth auth) |
X-CSRF-Token | Session cookie auth | Required for SWC; omit for API key integrations |
Example header set for model RPC:
POST /api/rpc/core.partner/search_read HTTP/1.1
Host: localhost:8080
Content-Type: application/json
X-Sumeru-Database: sumeru
X-Sumeru-Tenant: 1
Authorization: Bearer sk_your_key_hereResponse envelope
Every /api/rpc/ response uses:
{
"success": true,
"status_code": 200,
"timestamp": "2026-10-16T12:00:00+05:30",
"message": "OK",
"data": {},
"error": null
}success— business outcome (check this even when HTTP status is 200).status_code— mirrors the intended HTTP semantics on the envelope.data— method result on success;nullon failure.error— structured failure; shape depends on auth vs model RPC.
Model RPC error (example):
{
"success": false,
"status_code": 403,
"timestamp": "2026-10-16T12:00:00+05:30",
"message": "Access denied",
"data": null,
"error": {
"code": "ACCESS_DENIED",
"name": "sumeru.api.ACCESS_DENIED",
"message": "Access denied",
"context": { "code": "ACCESS_DENIED" }
}
}SWC reads error.code or error.context.code for redirects and messaging.
Auth error (auth.login, tenant denial, MFA):
{
"success": false,
"status_code": 401,
"timestamp": "2026-10-16T12:00:00+05:30",
"message": "Authentication failed",
"data": null,
"error": {
"code": "INVALID_CREDENTIALS",
"type": "AuthenticationError",
"context": {},
"debug": "Authentication failed."
}
}In dev_mode, debug may include more detail. Production returns a short generic debug string.
Responses may include X-Request-ID when the client sent one.
Browser clients (SWC)
The web app signs in at /web/login, then calls POST /api/rpc/{{model}}/{{method}} with cookie sumeru_session, X-CSRF-Token from window.__SWC_BOOTSTRAP__.csrfToken, and database/tenant headers from bootstrap. Integrators should prefer auth.login + Bearer instead of scraping cookies.
Production checklist
- Use HTTPS; rotate API keys via the UI or re-login; revoke compromised keys.
- Do not put keys in query strings or client-side storage.
- Respect ACLs: the key runs as its user — test with a dedicated integration account.
- Handle
429/ rate limits whenrate_limit_rpmis set.
What not to do
- Do not use flat
POST /api/rpcor legacy{ok, result}responses — they are removed. - Do not log raw
api_keyvalues or passwords. - Do not assume frozen error codes pre-1.0; check
error.codeand HTTP status.
Operations
Each operation uses the headers in Required headers and the response envelope.
Authenticate
Virtual auth endpoint (not an ORM model). POST only.
Request
POST /api/rpc/auth.login HTTP/1.1
Content-Type: application/json
X-Sumeru-Database: sumeru
X-Sumeru-Tenant: 1{
"context": { "lang": "en_US" },
"login": "user@example.com",
"password": "YOUR_PASSWORD"
}| Field | Required | Notes |
|---|---|---|
login | yes | Non-empty string |
password | yes | Non-empty string |
context | no | Optional; context.lang accepted for future i18n |
Respects auth.local_enabled (403 when password sign-in is disabled). Failed attempts use login lockout (same as web login). Users with TOTP required receive MFA_REQUIRED (403).
Success (200)
{
"success": true,
"status_code": 200,
"timestamp": "2026-10-16T12:00:00+05:30",
"message": "User authenticated successfully",
"data": {
"uid": 25,
"username": "user@example.com",
"name": "API User",
"session_id": "a1b2c3…",
"api_key": "sk_…"
},
"error": null
}A Set-Cookie for sumeru_session may be returned for browser clients. Never log api_key or raw passwords.
Failure (401) — error.code INVALID_CREDENTIALS, error.type AuthenticationError.
Model health
GET only. Same database, tenant, and authentication as model POST (Bearer or session + CSRF).
GET /api/rpc/core.partner/health HTTP/1.1
X-Sumeru-Database: sumeru
X-Sumeru-Tenant: 1
Authorization: Bearer sk_your_key_hereSuccess (200)
{
"success": true,
"status_code": 200,
"timestamp": "2026-10-16T12:00:00+05:30",
"message": "Model health OK",
"data": {
"model": "core.partner",
"registered": true,
"rpc_methods": ["call", "create", "create_many", "onchange", "read", "read_group", "search", "search_read", "unlink", "unlink_many", "write", "write_many"]
},
"error": null
}Unknown model → 404 with MODEL_NOT_FOUND. Wrong verb on other paths → 405.
Model RPC
{{model}}— registered ORM name (e.g.core.partner,crm.lead).{{method}}— public allowlist below.
Body: flat JSON per method. Optional top-level context, and for reads limit, offset, order where supported.
Auth: API key or session; then UserAllowedCompany for X-Sumeru-Tenant. Invalid API key → 401, message Invalid apikey. Tenant not allowed → 403.
Public methods summary
| Method | Required body fields | Optional | Typical data |
|---|---|---|---|
search | domain | context, limit, offset (via kwargs) | [{id, …}, …] |
search_read | domain, fields | limit, offset, order, context | Projected records |
read | ids | fields, context | Records |
create | values | context | New id (int) |
write | ids, values | context | true |
unlink | ids | context | true |
create_many | values (array) or records | context | [id, …] |
write_many | ids, values | context | true |
unlink_many | ids | context | true |
read_group | domain, groupby, fields (or single spec) | context | Group rows |
onchange | values, field | context | Onchange patch object |
call | id, method | vals, context | true or {redirect: "…"} |
Default limit is 500 (hard cap). Same ACL and record rules as the web UI.
Method request bodies
Replace {{model}} with any registered model (examples use core.partner unless noted).
search
Returns matching records (all stored columns subject to field ACL redaction).
| Required body | Optional | Typical data |
|---|---|---|
domain | context, limit, offset | Array of record maps |
Example (core.partner):
{
"domain": [["active", "=", true]],
"context": { "lang": "en_US" },
"limit": 50,
"offset": 0
}search_read
Search and project fields in one call.
| Required body | Optional | Typical data |
|---|---|---|
domain, fields | limit, offset, order, context | Projected records |
Example (core.partner):
{
"domain": [["customer_rank", ">", 0]],
"fields": ["name", "email", "phone", "company_id"],
"limit": 20,
"offset": 0,
"order": "name asc",
"context": { "lang": "en_US" }
}read
Read known ids.
| Required body | Optional | Typical data |
|---|---|---|
ids | fields, context | Records; omit fields for all allowed columns. Missing ids → NOT_FOUND. |
Example (core.partner):
{
"ids": [14, 15],
"fields": ["name", "email"],
"context": {}
}create
Create one record.
| Required body | Optional | Typical data |
|---|---|---|
values | context | New integer id in data |
Example (core.partner):
{
"values": {
"name": "New Partner Ltd",
"email": "hello@newpartner.example",
"company_id": 1
},
"context": {}
}write
Update records.
| Required body | Optional | Typical data |
|---|---|---|
ids, values | context | data: true |
Example (core.partner):
{
"ids": [14],
"values": { "phone": "+1-555-0199" },
"context": {}
}unlink
Delete records.
| Required body | Optional | Typical data |
|---|---|---|
ids | context | data: true |
Example (core.partner):
{
"ids": [99],
"context": {}
}create_many
Batch create.
| Required body | Optional | Typical data |
|---|---|---|
values (array) or records | context | data: [id, …] |
Example (core.partner):
{
"values": [
{ "name": "Batch A" },
{ "name": "Batch B" }
],
"context": {}
}write_many
Same body shape as write (shared values for all ids).
| Required body | Optional | Typical data |
|---|---|---|
ids, values | context | data: true |
Example (core.partner):
{
"ids": [14, 15],
"values": { "active": true },
"context": {}
}unlink_many
Same body shape as unlink.
| Required body | Optional | Typical data |
|---|---|---|
ids | context | data: true |
Example (core.partner):
{
"ids": [14, 15],
"context": {}
}read_group
Aggregations; measures sum or count.
| Required body | Optional | Typical data |
|---|---|---|
domain, groupby, fields (or spec) | context | Group rows |
Example (core.partner):
{
"domain": [["active", "=", true]],
"groupby": ["company_id"],
"fields": [
{ "name": "id_count", "field": "id", "measure": "count" }
],
"context": {}
}onchange
Form field change hooks (SWC uses this too).
| Required body | Optional | Typical data |
|---|---|---|
values, field | context | Onchange patch object |
Example (core.partner):
{
"values": { "name": "Partial", "country_id": 233 },
"field": "country_id",
"context": {}
}call
Invokes orm.RegisterObjectAction handlers (toolbar object buttons).
| Required body | Optional | Typical data |
|---|---|---|
id, method | vals, context | data: true or { redirect: "…" } |
Example (crm.lead):
{
"id": 42,
"method": "action_merge_wizard",
"vals": { "active_ids": "3,7" },
"context": {}
}Example model: POST /api/rpc/crm.lead/call. vals is a string map passed to orm.RunObjectAction.
search_read success (200) — example envelope:
{
"success": true,
"status_code": 200,
"timestamp": "2026-10-16T12:00:00+05:30",
"message": "OK",
"data": [
{
"id": 14,
"name": "Acme Corp",
"email": "contact@acme.example",
"phone": "+1-555-0100",
"company_id": 1
}
],
"error": null
}Removed legacy shapes
The following are not registered on the live router:
- Flat
POST /api/rpcwithmodel,method,args,kwargsin one body - JSON-RPC
paramswrapper - Response shape
{ "ok", "result", "error" }
Use path URLs and the envelope documented above.
Security
- RPC runs with the authenticated user (session or API key owner) and active tenant company in ORM context.
- Model ACL, record rules, field ACL, and portal RPC model restrictions apply.
- Rate limiting: config
rate_limit_rpmapplies to the/api/rpc/prefix and login (see configuration reference).
Observability
Prometheus: sumeru_rpc_requests_total, sumeru_rpc_duration_seconds (GET /metrics with system group).
See also
- Creating APIs — RPC vs custom HTTP vs object actions
- HTTP routes
- API keys
- Domain filters