Skip to navigation

Quickstart

Check your key, then make a mutation that is safe to retry.

By the end of this guide, you will have verified a workspace key and created an agent with an initial draft using curl. You will also know how to retry the request without creating the agent twice.

Before you start

You need:

  • a workspace in which you can open the Developers page;
  • a workspace API key stored outside your source code; and
  • curl.

The API is server-to-server. Do not put its key in browser or mobile application code.

1. Set the base URL and key

Create a key on the Developers page of the Rasen app, under API keys (Authentication). Then set two variables:

export RASEN_API_BASE="https://api.rasen.ai/v1"
export RASEN_API_KEY="<your API key>" # never commit it

2. Verify access

curl
curl -sS "$RASEN_API_BASE/context" -H "Authorization: Bearer $RASEN_API_KEY"

The answer names the key’s workspace and the capabilities that operations use:

{
"workspace_id": "ws_…",
"key_id": "key_…",
"creator_id": "usr_…",
"capabilities": ["config.read", "agents.write", "agents.publish", "knowledge.write", "tools.write",
"secrets.read", "secrets.manage", "numbers.assign", "calls.write", "calls.read", "usage.read"],
"api_version": "v1",
"workspace_state": "active",
"key_name": "ci",
"expires_at": null
}

3. A safe retry, end to end

Every mutation takes an Idempotency-Key. Choose a new one for each intended action, and keep it until you have the answer.

curl
KEY=$(uuidgen) # no uuidgen? KEY=$(python3 -c 'import uuid; print(uuid.uuid4())')
curl -sS -X POST "$RASEN_API_BASE/agents" \
-H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Support line", "resource_key": "support-line",
"initial_draft": {"prompt": "You are the support agent.",
"settings": {"language": "hinglish",
"first_message": "Namaste, how can I help?"}}}'
# The connection dropped before the answer arrived? Send the identical request again with the same $KEY.

The identity and initial draft are stored atomically. If an initial field is refused, neither is created. The repeat returns the original status and body with Idempotent-Replayed: true, and nothing happens twice. A different body under the same key is refused with 409 idempotency_key_reused after an intent has been recorded.

Save the returned agent.id. You will use it to read and edit the draft, select a voice, validate the result and publish a version in Agent lifecycle. To create an agent with its voice already chosen, list GET /voices without agent_id first and send the ID in initial_draft.voice.

4. The rules every call follows

TopicRuleWhat to do
Request IDEvery response has X-Request-Id; every error repeats it as error.request_id.Quote it to support.
Errors{"error": {"code", "message", "details", "request_id", "retry"}}.Branch on error.code, and for conflict on error.details.reason. Never on message. See Errors.
IdempotencyWrite operations need Idempotency-Key (1 to 255 characters).New key per intended action; the same key after a lost answer. See Idempotency.
RevisionsEdits need If-Match with the ETag of your last read. Missing: 428 revision_required. Stale: 409 draft_conflict or 409 conflict with reason: stale_revision.Read again, reapply your change, retry with the new ETag. See Revisions.
PagesLists return next_cursor; limit is 1 to 200, default 50; a cursor lasts 24 hours.Follow next_cursor until it is null. See Pagination.
FiltersRepeat a parameter for several values; at most 100 values in total. An empty value is refused, except metadata_value.Use POST /calls/search or POST /usage/query for larger sets. See Filters.
Rate limitsRateLimit-* headers on responses; excess gives 429 rate_limited with Retry-After.Wait Retry-After seconds. See Rate limits.

Next