---
title: create-a-byok-credential
product: vercel
url: /docs/rest-api/ai-gateway/create-a-byok-credential
canonical_url: "https://vercel.com/docs/rest-api/ai-gateway/create-a-byok-credential"
last_updated: 2026-10-28
type: reference
prerequisites:
  []
related:
  - /docs/rest-api
summary: Learn about create-a-byok-credential on Vercel.
install_vercel_plugin: npx plugins add vercel/vercel-plugin
---

# Create a BYOK credential

```http
POST /ai-gateway/byok-credentials
```

Create a new BYOK credential

## Authentication

**bearerToken**: HTTP bearer

## Query parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `teamId` | string | No | The Team identifier to perform the request on behalf of. |
| `slug` | string | No | The Team slug to perform the request on behalf of. |


## Request body

Required: No

Content-Type: `application/json`

```json
{
  "type": "object",
  "required": [
    "providerSlug",
    "name",
    "credential"
  ],
  "properties": {
    "ownerId": {
      "type": "string",
      "description": "The owner ID for this credential. Ignored for customer tokens, which always create in their own team."
    },
    "providerSlug": {
      "type": "string",
      "description": "The provider slug this credential is for (e.g., \"openai\", \"anthropic\")"
    },
    "name": {
      "type": "string",
      "description": "The developer-entered name for this credential",
      "maxLength": 100
    },
    "active": {
      "type": "boolean",
      "description": "Whether the credential is active and can be used",
      "default": true
    },
    "zeroDataRetention": {
      "type": "boolean",
      "description": "Whether the customer attested this external credential has a zero data retention policy",
      "default": false
    },
    "userId": {
      "type": "string",
      "description": "The ID of the user performing this action, used for Activity-log attribution."
    },
    "mappings": {
      "type": "array",
      "description": "Model mappings to create atomically with the credential (e.g. Azure deployments). One DynamoDB transaction holds the credential plus all mappings, so at most 99 mappings fit.",
      "items": {
        "type": "object",
        "required": [
          "gatewayModelSlug",
          "customModelId"
        ],
        "properties": {
          "gatewayModelSlug": {
            "type": "string",
            "description": "The AI Gateway model slug (e.g., \"openai/gpt-5.4\")"
          },
          "customModelId": {
            "type": "string",
            "description": "The customer's custom model ID (e.g., \"my-finetuned-gpt-5\")"
          }
        }
      }
    }
  }
}
```

## Example request

### TypeScript

```typescript
const response = await fetch('https://api.vercel.com/ai-gateway/byok-credentials?teamId=string&slug=string', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "ownerId": "example_id",
    "providerSlug": "example_id",
    "name": "Example Name",
    "active": "true",
    "zeroDataRetention": "true",
    "userId": "example_id",
    "mappings": [
      {
        "gatewayModelSlug": "string",
        "customModelId": "example_id"
      }
    ]
  }),
});

const data = await response.json();
console.log(data);
```

### Next.js

```typescript
'use server';

export async function callEndpoint() {
  const response = await fetch('https://api.vercel.com/ai-gateway/byok-credentials?teamId=string&slug=string', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.VERCEL_ACCESS_TOKEN}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      "ownerId": "example_id",
      "providerSlug": "example_id",
      "name": "Example Name",
      "active": "true",
      "zeroDataRetention": "true",
      "userId": "example_id",
      "mappings": [
        {
          "gatewayModelSlug": "string",
          "customModelId": "example_id"
        }
      ]
    }),
    next: { revalidate: 3600 }
  });

  if (!response.ok) {
    throw new Error('Request failed');
  }

  return response.json();
}
```

### cURL

```bash
curl -X POST 'https://api.vercel.com/ai-gateway/byok-credentials?teamId=string&slug=string' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d "{
    \"ownerId\": \"example_id\",
    \"providerSlug\": \"example_id\",
    \"name\": \"Example Name\",
    \"active\": \"true\",
    \"zeroDataRetention\": \"true\",
    \"userId\": \"example_id\",
    \"mappings\": [
      {
        \"gatewayModelSlug\": \"string\",
        \"customModelId\": \"example_id\"
      }
    ]
  }"
```

## Example response

```json
{
  "active": "false",
  "createdAt": "123",
  "credentialId": "example_id",
  "lastFourChars": "string",
  "name": "Example Name",
  "ownerId": "example_id",
  "providerSlug": "example_id",
  "updatedAt": "123",
  "zeroDataRetention": "false"
}
```

## Responses

### 201: No description

Content-Type: `application/json`

```json
{
  "type": "object",
  "required": [
    "active",
    "createdAt",
    "credentialId",
    "lastFourChars",
    "name",
    "ownerId",
    "providerSlug",
    "updatedAt",
    "zeroDataRetention"
  ],
  "properties": {
    "active": {
      "type": "boolean",
      "enum": [
        false,
        true
      ]
    },
    "createdAt": {
      "type": "number"
    },
    "credentialId": {
      "type": "string"
    },
    "lastFourChars": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "ownerId": {
      "type": "string"
    },
    "providerSlug": {
      "type": "string"
    },
    "updatedAt": {
      "type": "number"
    },
    "zeroDataRetention": {
      "type": "boolean",
      "enum": [
        false,
        true
      ]
    }
  }
}
```

### 400: One of the provided values in the request body is invalid.

### 401: The request is not authorized.

### 403: You do not have permission to access this resource.

### 404: No description

### 410: No description

### 429: No description

### 500: No description

---

## Related

- [ai-gateway endpoints](/docs/rest-api#ai-gateway)

- [REST API overview](/docs/rest-api)

- [OpenAPI spec](https://vercel.com/openapi.json) (machine-readable, all endpoints)

---

[View full sitemap](/docs/sitemap)


If you encounter incorrect information, can’t find what you need, need a capability Vercel doesn’t currently offer, or have any other feedback to report, please do it by following the instructions at https://vercel.com/feedback.md.
