Skip to content
1Claw Academy
Curriculum/Agents & Access Control2 minIntermediate · Lesson 1 of 15

Agents as first-class principals

Register an agent, get its automatic keypairs, and exchange its API key for a short-lived JWT.

In 1Claw an agent is a real principal with its own identity, not a shared human login. An agent can authenticate three ways: an API key with the ocv_ prefix, mutual TLS, or OIDC federation. This lesson uses the API key path because it's the fastest to run end to end.

  • API key: ocv_ random value, argon2-hashed, shown once at creation
  • mTLS: client certificate identity for infrastructure agents
  • OIDC: federate an external identity provider into 1Claw
Concept

When you register an agent, 1Claw auto-generates an Ed25519 signing keypair and a P-256 ECDH keypair. Private keys live HSM-encrypted in the __agent-keys vault; only the public keys sit on the agent record.

  1. 1

    Use the same 1ck_ key from Foundations. Agent keys cannot create other agents.

    bash
    export ONECLAW_API_KEY="1ck_your_key_here"
  2. 2

    Register an agent. The plaintext ocv_ key is returned once in this response and never again. Use the vault UUID from Foundations (1claw vault list) and export it: export VAULT_ID=...

    bash
    export VAULT_ID="your-vault-uuid-here"
    
    AGENT_RESPONSE=$(curl -s -X POST https://api.1claw.co/v1/agents \
      -H "Authorization: Bearer $ONECLAW_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"name":"web-backend","token_ttl_seconds":900,"vault_ids":["'$VAULT_ID'"]}')
    
    echo "$AGENT_RESPONSE"
  3. 3

    Extract the agent id and api_key from the response. The response looks like: {"agent":{"id":"7e3ce911-...","name":"web-backend",...},"api_key":"ocv_..."}. Save both values as env vars.

    bash
    export ONECLAW_AGENT_ID=$(echo "$AGENT_RESPONSE" | jq -r .agent.id)
    export ONECLAW_AGENT_KEY=$(echo "$AGENT_RESPONSE" | jq -r .api_key)
    echo "Agent ID: $ONECLAW_AGENT_ID"
    echo "Agent Key: $ONECLAW_AGENT_KEY"
  4. 4

    Exchange the agent credentials for a short-lived JWT. This endpoint needs no bearer token; the credentials in the body are the auth.

    bash
    TOKEN=$(curl -s -X POST https://api.1claw.co/v1/auth/agent-token \
      -H "Content-Type: application/json" \
      -d '{"agent_id":"'$ONECLAW_AGENT_ID'","api_key":"'$ONECLAW_AGENT_KEY'"}' | jq -r .access_token)
  5. 5

    Confirm the token works by fetching the agent's own profile. You should see the ssh_public_key and ecdh_public_key fields.

    bash
    curl -s https://api.1claw.co/v1/agents/me -H "Authorization: Bearer $TOKEN"

You now have a registered agent and a fresh JWT bound to its vaults and TTL. Later calls use a Bearer JWT like this one; you will refresh it when policies change.

Decide

A team is migrating a batch job to an agent identity. They ask whether to reuse the service account credential the job already has, since it is already scoped correctly.

What do you advise?

Check your understanding

3 questions
1

How many times is the plaintext ocv_ API key returned?

2

Which endpoint turns an agent_id plus api_key into a JWT?

3

What two keypairs does 1Claw auto-generate for a new agent?