Docs/Getting Started

Getting Started with Tork

Get up and running with Tork in 5 minutes. This guide walks you through account setup, API key creation, SDK installation, and making your first API call.

Prerequisites

Before you begin, make sure you have:

  • A Tork account (we'll create one in Step 1)
  • Python 3.10+ or Node.js 18+ installed
  • A terminal or command prompt
1

Create Your Account

Sign up for a free Tork account to get started. The free tier includes 1,000 API calls per month—plenty to explore and test the platform.

OAuth Support
You can sign up using Google or GitHub for faster onboarding. Your organization and first API key are created automatically.
2

Get Your API Key

After signing up, you'll be automatically redirected to your dashboard where your first API key is ready. You can also create additional keys from the API Keys page.

Finding Your API Key

  1. Go to your Dashboard → API Keys
  2. Your default API key will be shown (prefix only for security)
  3. Click "Create New Key" if you need additional keys
  4. Copy the full key when shown—it won't be displayed again
Keep Your API Key Secret
Never commit API keys to version control or expose them in client-side code. Use environment variables instead.
3

Install the SDK

This installs tork-governance, the on-device package, whose entry class is Tork. It governs on your machine and returns a local result; the API key from step 2 is not used by it, and its decisions do not appear in your dashboard. Step 4 shows both paths side by side.

bash
pip install tork-governance
Direct API Access
Don't want to use an SDK? You can call the Tork API directly using any HTTP client. See the API Reference for details.
4

Make Your First API Call

Now let's make your first governance check. There are two ways to do it, and they differ in where the decision is made and whether it leaves evidence.

On-device vs server-governed

The Python and JavaScript blocks below use tork-governance and decide on your machine. tork-governance makes the governance decision on your machine. PII detection, redaction and the returned verdict are computed on-device. With no API key it makes zero network calls: prompts, completions and detected PII values never leave the machine, and nothing appears in your dashboard.

The cURL block and @torknetwork/sdk send your content to Tork, which decides server-side and writes a receipt to your dashboard as capture_mode=cloud attested_by=tork. Both families can populate a dashboard; that is the one whose row records a decision Tork executed rather than a claim you attested.

Local governance is free and unlimited — decisions made on your own machine are never metered. Evidence is what is metered: attestations, receipts and anchoring.

Python — on-device (tork-governance)

example.pypython
from tork_governance import Tork

# No API key: the decision is made on this machine and nothing
# is sent anywhere. This is free and unlimited.
tork = Tork()

result = tork.govern("Check this text for PII: john@example.com")

print(result.action)              # GovernanceAction.REDACT
print(result.output)              # "Check this text for PII: [EMAIL_REDACTED]"
print(result.receipt.receipt_id)  # "rcpt_..." — a LOCAL receipt, not in your dashboard

JavaScript — on-device (tork-governance)

example.jsjavascript
import { Tork } from 'tork-governance';

// No API key: the decision is made on this machine and nothing
// is sent anywhere. This is free and unlimited.
const tork = new Tork();

// govern() is synchronous — there is no network call to await.
const result = tork.govern('Check this text for PII: john@example.com');

console.log(result.action);            // "redact"
console.log(result.output);            // "Check this text for PII: [EMAIL_REDACTED]"
console.log(result.receipt.receiptId); // "rcpt_..." — a LOCAL receipt, not in your dashboard

cURL — server-governed (Tork decides)

terminalbash
curl -X POST https://tork.network/api/v1/govern \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Check this text for PII: john@example.com"
  }'
5

Understand the Response

The /v1/govern REST endpoint — the cURL path above — returns a JSON response with the governance decision and details about any detected PII:

response.jsonjson
{
  "action": "redact",
  "redacted": "Check this text for PII: [EMAIL]",
  "original": "Check this text for PII: john@example.com",
  "pii_detected": [
    {
      "type": "email",
      "value": "john@example.com",
      "position": { "start": 27, "end": 43 },
      "confidence": 0.99
    }
  ],
  "policy_applied": "default",
  "processing_time_ms": 45,
  "request_id": "req_abc123"
}

Response Fields

These are the REST response fields. The on-device SDK returns a different shape: action, output, pii, receipt and report, with the governed text in output rather than a redacted field. In Python that result is a dataclass, so read it with result.action, not result['action'].

FieldTypeDescription
actionstringallow, redact, or deny
redactedstringThe text with PII replaced by placeholders
pii_detectedarrayList of detected PII with types and positions
policy_appliedstringName of the governance policy that was applied
processing_time_msnumberProcessing time in milliseconds
You're Ready!
You've made your first governance call and the detected email was redacted. If you ran the on-device blocks, that happened entirely on your machine and your dashboard stays empty. If you ran the cURL call, Tork made the decision and wrote a receipt.

Using Environment Variables

For production use, store your API key in an environment variable instead of hardcoding it. Note what the key does and does not change here: the on-device SDK still makes every decision locally with or without one. A key only governs whether a metadata-only attestation is reported.

python
import os
from tork_governance import Tork

# No key: local governance only, nothing reported.
tork = Tork()

# With a key: the decision is still made locally; an attestation
# of it is reported. Reads TORK_API_KEY from the environment.
tork = Tork(api_key=os.environ.get('TORK_API_KEY'))
Attestation reporting status
Supply an API key and the SDK additionally reports a metadata-only attestation of each decision — the action taken, PII type labels and counts, a risk classification, policy labels and a salted fingerprint. It never sends input text, output text or PII values. The decision itself is still made on-device and is never delayed or changed by reporting. Those attestations appear in your dashboard and are included in the daily on-chain anchor — each one recorded as a client attestation (capture_mode=edge, attested_by=client), a claim Tork recorded but did not execute and cannot independently verify. Requires tork-governance 0.24.0+ (PyPI) or 0.11.0+ (npm).

A decision reported by an on-device SDK is recorded as a client attestation (capture_mode=edge, attested_by=client): a claim Tork recorded but did not execute and cannot independently verify. A decision made by @torknetwork/sdk is recorded as capture_mode=cloud, attested_by=tork — Tork made that call itself. Both are equally immutable once anchored; they differ in what is immutable. A client attestation freezes your claim. A server-governed receipt freezes Tork's own decision.

Next Steps

Now that you've made your first API call, explore these resources to learn more:

Common Issues

401 Unauthorized

Only the server-governed paths (cURL / @torknetwork/sdk) can return this — the on-device SDK never authenticates without a key. Check that:

  • The API key is correctly copied (no extra spaces)
  • The key hasn't been revoked in your dashboard
  • You're using Bearer prefix in the Authorization header

429 Rate Limited

You've exceeded your plan's API call limit. Options:

  • Wait for your billing period to reset
  • Upgrade your plan for higher limits
  • Implement caching to reduce API calls

Connection Errors

If you're having trouble connecting:

  • Check your internet connection
  • Verify you're using HTTPS (not HTTP)
  • Check tork.network for current availability