---
updatedAt: 2026-07-29T08:25:42.000Z
agentTools:
  projectIndex: https://docs.d-id.com/llms.txt
---

# Authorization Options

Attach encrypted credentials to a server tool without exposing them in the tool definition

## Overview

Server tools authenticate against your external API using a credential you store with `POST /secrets`. Credentials are encrypted at rest and never appear in the tool object or any API response — the tool definition holds only a reference (`secret_id`). Four credential types are supported: bearer, API key, basic, and OAuth2.

Client tools do not use this flow. They run in the user's browser; whatever auth the browser already has (cookies, session storage) is available to the handler directly.

You create the secret once and reference it from every tool that uses it. When the agent invokes the tool, the `secret_id` is resolved and the appropriate header is attached to the outbound request.

## Authentication Types

| Type      | Use for                                                                                                | Header sent                                |
| :-------- | :----------------------------------------------------------------------------------------------------- | :----------------------------------------- |
| `bearer`  | OAuth2-style tokens or any pre-issued bearer credential.                                               | `Authorization: Bearer <token>`            |
| `api_key` | APIs that take a key in a custom header.                                                               | Configurable (default `X-API-Key`)         |
| `basic`   | Username + password APIs.                                                                              | `Authorization: Basic <base64(user:pass)>` |
| `oauth2`  | Three-legged OAuth2 flows where access tokens must be refreshed automatically. Created in D-ID Studio. | `Authorization: Bearer <access_token>`     |

## Create a Secret

Bearer, API key, and basic secrets are created with `POST /secrets`. Each type has its own request shape; the response is the same — an `id` you reference from the tool. OAuth2 secrets follow a different path — see the [OAuth2](#oauth2) section below.

### Bearer

```yaml Request
curl -X POST "https://api.d-id.com/secrets" \
  -H "Authorization: Basic <YOUR KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "bearer",
    "provider": "Weather API",
    "token": "wk_live_abc123"
  }'
```

```json Response
{
  "id": "sec_o0kaqea3v",
  "provider": "Weather API",
  "type": "bearer",
  "sanitized_secret": "•••••••••",
  "created_at": "2026-05-20T12:00:00.000Z"
}
```

### API Key

```yaml Request
curl -X POST "https://api.d-id.com/secrets" \
  -H "Authorization: Basic <YOUR KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "api_key",
    "provider": "Storefront",
    "api_key": "sk_live_abc123",
    "header_name": "X-API-Key"
  }'
```

`header_name` is optional — omit it to send the key in the default `X-API-Key` header.

### Basic

```yaml Request
curl -X POST "https://api.d-id.com/secrets" \
  -H "Authorization: Basic <YOUR KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "basic",
    "provider": "Internal CRM",
    "username": "service-account",
    "password": "rotated-monthly"
  }'
```

### OAuth2

OAuth2 secrets are created through D-ID Studio rather than the API. The authorization flow requires a user-facing redirect to the provider's consent screen, so Studio runs the dance for you: you supply the OAuth client details, Studio opens the provider's authorize page, and the resulting tokens are stored as a secret tied to your account.

Once the secret exists, treat it like any other — reference it from a tool's `auth.secret_id` field via the API. Access-token refresh happens automatically against the configured `token_url`; you do not need to re-authorize unless the refresh token itself is revoked.

## Reference the Secret from a Tool

Once the secret exists, attach it to the tool with `auth.secret_id`.

```yaml Request
curl -X POST "https://api.d-id.com/tools" \
  -H "Authorization: Basic <YOUR KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "get_current_weather",
    "description": "Get current weather for a city",
    "provider": "Weather API",
    "schema": { "parameters": { "type": "object", "properties": { "city": { "type": "string" } }, "required": ["city"] } },
    "config": { "type": "server", "url": "https://api.weatherapi.example.com/current", "method": "GET" },
    "auth": { "secret_id": "sec_o0kaqea3v" }
  }'
```

The same `secret_id` can be referenced from any number of tools. Rotating the credential happens in one place — `PUT /secrets/{id}` — and every tool that references it picks up the new value on the next call.

## FAQ

<CoolAccordionBox>
  <CoolAccordion title="Can a tool have no auth at all?">
    <p>Yes. Omit the <code>auth</code> field when creating the tool — the request goes out without any auth header. Use this for public endpoints.</p>
  </CoolAccordion>

  <CoolAccordion title="How are secrets stored?">
    <p>Credentials are encrypted at rest and never returned in API responses — list and get endpoints return a <code>sanitized_secret</code> placeholder (<code>•••••••••</code>) instead of the value.</p>
  </CoolAccordion>

  <CoolAccordion title="What happens during OAuth2 token refresh?">
    <p>The access token is checked before each tool call. If it's expired, the stored refresh token is used against the configured <code>token_url</code> and the secret is updated with the new tokens automatically.</p>
  </CoolAccordion>

  <CoolAccordion title="Can I change a tool's secret without recreating the tool?">
    <p>Yes. <code>PUT /tools/\{toolId\}</code> with a new <code>auth.secret_id</code> swaps the reference. The tool itself doesn't change.</p>
  </CoolAccordion>

  <CoolAccordion title="Why is my tool returning 401 on every call?">
    <p>The credential stored in the secret no longer matches what your endpoint expects — usually because the key was rotated or revoked upstream. Update the secret with <code>PUT /secrets/\{id\}</code> and the next tool call will use the new value.</p>
  </CoolAccordion>

  <CoolAccordion title="Why does the LLM never see the credential?">
    <p>By design. The LLM only sees the tool's name, description, and schema. Credentials are resolved server-side and attached to the outbound request — they never enter the conversation context.</p>
  </CoolAccordion>
</CoolAccordionBox>