OpenAPI
Configure and document API authentication methods with OpenAPI security schemes
Docs Kit automatically handles authentication for API endpoints based on OpenAPI security schemes. Configure security schemes in your spec, and the Try It modal will provide appropriate authentication inputs.
Define security schemes in the components.securitySchemes section of your OpenAPI spec:
{
"components": {
"securitySchemes": {
"ApiKeyAuth": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key"
},
"BearerAuth": {
"type": "http",
"scheme": "bearer"
}
}
}
}
API keys can be passed in headers, query parameters, or cookies.
{
"securitySchemes": {
"ApiKeyHeader": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key",
"description": "API key from dashboard"
}
}
}
Usage in Try It:
X-API-Key: sk_live_abc123def456
{
"securitySchemes": {
"ApiKeyQuery": {
"type": "apiKey",
"in": "query",
"name": "api_key"
}
}
}
Usage in Try It:
GET /api/users?api_key=sk_live_abc123def456
{
"securitySchemes": {
"ApiKeyCookie": {
"type": "apiKey",
"in": "cookie",
"name": "api_key"
}
}
}
Usage in Try It:
Cookie: api_key=sk_live_abc123def456
For JWT tokens and OAuth 2.0 bearer tokens:
{
"securitySchemes": {
"BearerAuth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT",
"description": "JWT token from /auth/login endpoint"
}
}
}
Usage in Try It:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Username and password authentication:
{
"securitySchemes": {
"BasicAuth": {
"type": "http",
"scheme": "basic",
"description": "Username and password"
}
}
}
Usage in Try It:
Users enter username and password separately. Docs Kit automatically encodes to Base64:
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Various OAuth 2.0 flows:
{
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://auth.example.com/oauth/authorize",
"tokenUrl": "https://auth.example.com/oauth/token",
"scopes": {
"read": "Read access",
"write": "Write access",
"admin": "Admin access"
}
}
}
}
}
}
{
"securitySchemes": {
"OpenID": {
"type": "openIdConnect",
"openIdConnectUrl": "https://auth.example.com/.well-known/openid-configuration"
}
}
}
Apply security to all endpoints:
{
"security": [
{
"BearerAuth": []
}
]
}
All endpoints require Bearer authentication unless overridden.
Override security for specific endpoints:
{
"paths": {
"/public/health": {
"get": {
"summary": "Health check",
"security": [],
"responses": {...}
}
},
"/users": {
"get": {
"summary": "List users",
"security": [
{
"BearerAuth": []
}
],
"responses": {...}
}
}
}
}
The /public/health endpoint requires no authentication (empty array), while /users requires Bearer token.
Allow multiple authentication methods:
{
"paths": {
"/users": {
"get": {
"summary": "List users",
"security": [
{
"BearerAuth": []
},
{
"ApiKeyAuth": []
}
],
"responses": {...}
}
}
}
}
Users can authenticate with either Bearer token OR API key.
For OAuth 2.0, specify required scopes:
{
"paths": {
"/admin/users": {
"delete": {
"summary": "Delete user (admin only)",
"security": [
{
"OAuth2": ["admin", "write"]
}
],
"responses": {...}
}
}
}
}
Requires both admin and write scopes.
The Try It modal displays an "Authentication" tab showing all required security schemes for the endpoint.
Based on auth type, appropriate input fields appear:
API Key:
���������������������������������
X-API-Key
�����������������������������
sk_live_abc123...
�����������������������������
���������������������������������
Bearer Token:
���������������������������������
Bearer Token
�����������������������������
eyJhbGc...
�����������������������������
���������������������������������
Basic Auth:
���������������������������������
Username
�����������������������������
john@example.com
�����������������������������
Password
�����������������������������
""""""""
�����������������������������
���������������������������������
Authentication values are saved in browser localStorage and persist across:
Users don't need to re-enter credentials repeatedly.
Add helpful descriptions to security schemes:
{
"securitySchemes": {
"ApiKeyAuth": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key",
"description": "API key from your dashboard. Go to Settings > API Keys to generate a new key."
}
}
}
Descriptions appear as helper text in the Try It modal.
For bearer tokens, specify the format:
{
"securitySchemes": {
"BearerAuth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
}
}
}
Helps users understand what type of token is expected.
For OAuth 2.0, clearly document what each scope allows:
{
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"scopes": {
"read": "Read user data and public resources",
"write": "Create and update resources",
"delete": "Delete resources (requires admin review)",
"admin": "Full admin access to all resources"
}
}
}
}
}
}
Choose the right auth method for your use case:
{
"components": {
"securitySchemes": {
"ApiKey": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key"
}
}
},
"security": [
{
"ApiKey": []
}
]
}
{
"components": {
"securitySchemes": {
"JWT": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
},
"ApiKey": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key"
}
}
},
"security": [
{
"JWT": []
},
{
"ApiKey": []
}
]
}
Users can authenticate with either JWT OR API key.
{
"components": {
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://auth.example.com/authorize",
"tokenUrl": "https://auth.example.com/token",
"scopes": {
"read": "Read access",
"write": "Write access"
}
}
}
}
}
},
"paths": {
"/users": {
"get": {
"security": [{ "OAuth2": ["read"] }]
},
"post": {
"security": [{ "OAuth2": ["write"] }]
}
}
}
}
Use the Try It modal to test authentication:
Open Try It modal and navigate to Authentication tab. Enter your API key, token, or credentials.
Fill in any required parameters and click "Send Request".
Check for successful authentication (200 status) or authentication errors (401/403).
If authentication fails:
You've completed the Docs Kit documentation! Start building your documentation site with these guides.