> This page is for version 2025-09-18 (default).
> For other versions, use one of these documentation indexes:
> - 2025-09-18 (default): https://apidocs.polytomic.com/2025-09-18/llms.txt
> - 2024-02-08: https://apidocs.polytomic.com/2024-02-08/llms.txt
> - 2023-04-25: https://apidocs.polytomic.com/2023-04-25/llms.txt
> - 2022-12-12: https://apidocs.polytomic.com/2022-12-12/llms.txt
> - 2021-05-23: https://apidocs.polytomic.com/2021-05-23/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://apidocs.polytomic.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://apidocs.polytomic.com/_mcp/server.

# Create Temporary Credential

POST https://app.polytomic.com/api/temporary-credentials
Content-Type: application/json

Issues a non-renewable credential with a bounded lifetime for a user or Harbor.

The response contains the credential secret once. Store it securely and send it
as a Bearer token in the `Authorization` header.

Set `subject.type` to `user` to issue a credential for your authenticated user.
Omit `organization_id` and `user_id`; Polytomic derives both values from your
credential. Set `mode` to `read_only` to limit the credential to the
intersection of the user's current permissions and read-only actions. A
read-only caller can issue only read-only credentials.

Partner callers must provide both `organization_id` and `user_id`. The target
must be an active user in an organization owned by the partner. User subjects
must be application users; Harbor-only users continue to use Harbor
credentials.

User credentials resolve the subject's current permissions on every request.
Permission changes take effect immediately, and deleting the user invalidates
the credential.

Set `subject.type` to `harbor` and provide the Harbor ID in `harbor_id`. The
credential uses the Harbor's current connection access on every request;
changes take effect immediately. Missing and deleted Harbors cannot be
targeted.

A temporary credential stops authenticating at `expires_at`. It cannot be
refreshed, extended, or used to create another temporary credential. Create a
new credential with a durable authorized credential when you need a later
expiration.

Each organization may have up to 1,000 active temporary credentials. The
endpoint returns `429 Too Many Requests` at the limit. Expired credentials stop
counting toward the limit immediately, before periodic cleanup removes them.

> ⚠️ Session names are audit labels
>
> Use `session_name` only for non-sensitive job or agent-session correlation.
> Do not include secrets or personal data.

Polytomic periodically removes expired credential records. API usage history
keeps its credential ID according to the normal API usage retention period.

Reference: https://apidocs.polytomic.com/api-reference/temporary-credentials/create

## Authentication

- `Authorization` header (bearer token, required) — Bearer user API key
- `Authorization` header (bearer token, required) — Bearer partner API key

## Request

### Body (application/json)

This endpoint expects a CreateTemporaryCredentialRequest.

- `subject` (TemporaryCredentialSubject, required)
- `duration_seconds` (integer, optional, nullable, default: 3600) — Credential lifetime in seconds. Defaults to 3600 (1 hour); minimum 600 and maximum 14400.
- `session_name` (string, optional) — Optional audit correlation label, limited to 128 characters. Do not include secrets or personal data.

## Response

### 200

OK

- `data` (TemporaryCredentialResponse, optional)

## Errors

### 400 Bad Request Error

Bad Request

- `key` (string, optional)
- `message` (string, optional)
- `metadata` (map from string to any, optional)
- `status` (integer, optional)

### 401 Unauthorized Error

Unauthorized

- `key` (string, optional)
- `message` (string, optional)
- `metadata` (map from string to any, optional)
- `status` (integer, optional)

### 403 Forbidden Error

Forbidden

- `key` (string, optional)
- `message` (string, optional)
- `metadata` (map from string to any, optional)
- `status` (integer, optional)

### 404 Not Found Error

Not Found

- `key` (string, optional)
- `message` (string, optional)
- `metadata` (map from string to any, optional)
- `status` (integer, optional)

### 429 Too Many Requests Error

Too Many Requests

- `key` (string, optional)
- `message` (string, optional)
- `metadata` (map from string to any, optional)
- `status` (integer, optional)

### 500 Internal Server Error

Internal Server Error

- `key` (string, optional)
- `message` (string, optional)
- `metadata` (map from string to any, optional)
- `status` (integer, optional)

## Types

### TemporaryCredentialSubject

- `type` (enum, required) — Authority subject type. Use user for current user authority or harbor for a Harbor.
  - Allowed values: `user`, `harbor`
- `harbor_id` (string, optional) — Target Harbor for a Harbor credential.
- `mode` (enum, optional) — Authority mode for a user credential. Defaults to user. Harbor subjects do not accept this field.
  - Allowed values: `user`, `read_only`
- `organization_id` (string, optional) — Target organization for broker-issued credentials. Omit when the caller's organization determines the target.
- `user_id` (string, optional) — Target user for broker-issued user credentials. Omit for user self-issuance.

### TemporaryCredentialResponse

- `access_token` (string, optional) — Temporary credential secret. This value is returned only once; store it securely.
- `expires_at` (datetime, optional) — Timestamp after which the credential is rejected.
- `id` (string, optional) — Temporary credential identifier used for usage attribution.
- `token_type` (string, optional) — Authorization scheme for the access token. Always Bearer.

## Examples

**Request**

```json
{
  "subject": {
    "type": "user"
  }
}
```

**Response**

```json
{
  "data": {
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.examplePayload.signature",
    "expires_at": "2024-01-15T09:30:00Z",
    "id": "248df4b7-aa70-47b8-a036-33ac447e668d",
    "token_type": "Bearer"
  }
}
```

**SDK Code**

```python
import requests

url = "https://app.polytomic.com/api/temporary-credentials"

payload = { "subject": { "type": "user" } }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://app.polytomic.com/api/temporary-credentials';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"subject":{"type":"user"}}'
};

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

```go
package main

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

func main() {

	url := "https://app.polytomic.com/api/temporary-credentials"

	payload := strings.NewReader("{\n  \"subject\": {\n    \"type\": \"user\"\n  }\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	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
require 'uri'
require 'net/http'

url = URI("https://app.polytomic.com/api/temporary-credentials")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"subject\": {\n    \"type\": \"user\"\n  }\n}"

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

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

HttpResponse<String> response = Unirest.post("https://app.polytomic.com/api/temporary-credentials")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"subject\": {\n    \"type\": \"user\"\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.polytomic.com/api/temporary-credentials', [
  'body' => '{
  "subject": {
    "type": "user"
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.polytomic.com/api/temporary-credentials");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"subject\": {\n    \"type\": \"user\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["subject": ["type": "user"]] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://app.polytomic.com/api/temporary-credentials")! 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()
```