> Call POST /v1/check before a tool that writes. DENY means do not invoke the tool. For clean Markdown of any page, append .md to the page URL. For the complete index, fetch https://docs.withwrit.com/llms.txt.

# Issue a free API key and tenant

POST https://api.withwrit.com/v1/keys
Content-Type: application/json

No auth. This is how a tenant is born: POST an email and get back an
API key (`writ_...`), a tenant ID, and the tenant's default verb
policy. The **first** key issued for an email creates a new tenant and
also returns that tenant's **sponsor token** (`writ_sp_...`) — shown
exactly once, never recoverable. The sponsor token is the human half
of the credential model: it mints grants and operates the kill
switch. Pass `inviteCode` to join an existing tenant instead of
creating your own — joining members do not receive the sponsor token.

Rate-limited to 10 keys per hour per client IP. Without this, the
free monthly check quota would be trivially bypassed by minting keys.

Pass `principal_id` to issue the key to an identity-directory
principal (see Principals); the id must belong to a live principal
in the tenant. Without one, the key lands on the tenant's
`default` principal, created on first use.


Reference: https://docs.withwrit.com/api-reference/account/issue-a-free-api-key-and-tenant

## Servers

- `https://api.withwrit.com` (Writ gate, default)
- `https://j72ckh66ukck2kcbq3oiwxaalm0olxwb.lambda-url.us-east-1.on.aws` (Direct Lambda Function URL (fallback))

## Request

### Body (application/json)

This endpoint expects an object.

- `email` (string, required) — Contact email for the key. The first key for an email creates the tenant.
- `tenantName` (string, optional) — Display name for a newly created tenant.
- `inviteCode` (string, optional) — Team invite code (writ_inv_...) to join an existing tenant instead of creating one.
- `principal_id` (string, optional) — Identity-directory principal (prn_...) the key is issued to. Must be a live principal in the tenant.

## Response

### 201

apiKey, tenantId, sponsorToken (first key of a tenant only), defaultPolicy, monthlyChecks (10,000 free receipts per tenant per month)

## Errors

### 400 Bad Request Error

Bad request — the body is not a JSON object, the email is missing or malformed, or the inviteCode is invalid.

### 429 Too Many Requests Error

Too many keys requested from this address this hour. Wait and retry.

## Examples

**Request**

```json
{
  "email": "ops@example.com",
  "tenantName": "Acme support"
}
```

**Response**

```json
{
  "apiKey": "writ_7hK2xQ9mZp4v...",
  "defaultPolicy": {
    "admit": "require_grant",
    "prescribe": "require_grant",
    "provision": "require_grant",
    "refund": "require_grant",
    "verify": "require_grant",
    "verify_human": "require_grant"
  },
  "email": "ops@example.com",
  "monthlyChecks": 10000,
  "plan": "free",
  "principalId": "prn_9d2f4a1b2c3d",
  "sponsorToken": "writ_sp_9dKx2mQv...",
  "sponsorTokenNote": "Shown once and never recoverable. The sponsor token approves grants and revokes principals for this tenant. Store it somewhere safe.",
  "tenantId": "ten_3fa8b91c2d44"
}
```

**SDK Code**

```python Account_issueAFreeApiKeyAndTenant_example
import requests

url = "https://api.withwrit.com/v1/keys"

payload = {
    "email": "ops@example.com",
    "tenantName": "Acme support"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Account_issueAFreeApiKeyAndTenant_example
const url = 'https://api.withwrit.com/v1/keys';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"email":"ops@example.com","tenantName":"Acme support"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Account_issueAFreeApiKeyAndTenant_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.withwrit.com/v1/keys"

	payload := strings.NewReader("{\n  \"email\": \"ops@example.com\",\n  \"tenantName\": \"Acme support\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Account_issueAFreeApiKeyAndTenant_example
require 'uri'
require 'net/http'

url = URI("https://api.withwrit.com/v1/keys")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"email\": \"ops@example.com\",\n  \"tenantName\": \"Acme support\"\n}"

response = http.request(request)
puts response.read_body
```

```java Account_issueAFreeApiKeyAndTenant_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.withwrit.com/v1/keys")
  .header("Content-Type", "application/json")
  .body("{\n  \"email\": \"ops@example.com\",\n  \"tenantName\": \"Acme support\"\n}")
  .asString();
```

```php Account_issueAFreeApiKeyAndTenant_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.withwrit.com/v1/keys', [
  'body' => '{
  "email": "ops@example.com",
  "tenantName": "Acme support"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Account_issueAFreeApiKeyAndTenant_example
using RestSharp;

var client = new RestClient("https://api.withwrit.com/v1/keys");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"email\": \"ops@example.com\",\n  \"tenantName\": \"Acme support\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Account_issueAFreeApiKeyAndTenant_example
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "email": "ops@example.com",
  "tenantName": "Acme support"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.withwrit.com/v1/keys")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```