> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/connect/create-nodes/build-your-node/reference/credentials-files.md).

# Credentials files

The credentials file defines the authorization methods for the node. The settings in this file affect what n8n displays in the **Credentials** modal, and must reflect the authentication requirements of the service you're connecting to.

In the credentials file, you can use all the [n8n UI elements](/connect/create-nodes/build-your-node/reference/node-ui-elements.md). n8n encrypts the data that's stored using credentials using an encryption key.

## Structure of the credentials file <a href="#structure-of-the-credentials-file" id="structure-of-the-credentials-file"></a>

The credentials file follows this basic structure:

1. Import statements
2. Create a class for the credentials
3. Within the class, define the properties that control authentication for the node.

### Outline structure <a href="#outline-structure" id="outline-structure"></a>

```js
import {
	IAuthenticateGeneric,
	ICredentialTestRequest,
	ICredentialType,
	INodeProperties,
} from 'n8n-workflow';

export class ExampleNode implements ICredentialType {
	name = 'exampleNodeApi';
	displayName = 'Example Node API';
	documentationUrl = '';
	properties: INodeProperties[] = [
		{
			displayName: 'API Key',
			name: 'apiKey',
			type: 'string',
			default: '',
		},
	];
	authenticate: IAuthenticateGeneric = {
		type: 'generic',
		properties: {
    		// Can be body, header, qs or auth
			qs: {
        		// Use the value from `apiKey` above
				'api_key': '={{$credentials.apiKey}}'
			}

		},
	};
	test: ICredentialTestRequest = {
		request: {
			baseURL: '={{$credentials?.domain}}',
			url: '/bearer',
		},
	};
}
```

## Parameters <a href="#parameters" id="parameters"></a>

### `name` <a href="#name" id="name"></a>

String. The internal name of the object. Used to reference it from other places in the node.

### `displayName` <a href="#displayname" id="displayname"></a>

String. The name n8n uses in the GUI.

### `documentationUrl` <a href="#documentationurl" id="documentationurl"></a>

String. URL to your credentials documentation.

### `properties` <a href="#properties" id="properties"></a>

Each object contains:

* `displayName`: the name n8n uses in the GUI.
* `name`: the internal name of the object. Used to reference it from other places in the node.
* `type`: the data type expected, such as `string`.
* `default`: the URL that n8n should use to test credentials.

### `authenticate` <a href="#authenticate" id="authenticate"></a>

* `authenticate`: Object. Contains objects that tell n8n how to inject the authentication data as part of the API request.

#### `type` <a href="#type" id="type"></a>

String. If you're using an authentication method that sends data in the header, body, or query string, set this to `'generic'`.

#### `properties` <a href="#properties" id="properties"></a>

Object. Defines the authentication methods. Options are:

* `body`: Object. Sends authentication data in the request body. Can contain nested objects.

```typescript
authenticate: IAuthenticateGeneric = {
	type: 'generic',
	properties: {
		body: {
			username: '={{$credentials.username}}',
			password: '={{$credentials.password}}',
		},
	},
};
```

* `header`: Object. Send authentication data in the request header.

```typescript
authenticate: IAuthenticateGeneric = {
	type: 'generic',
	properties: {
		header: {
			Authorization: '=Bearer {{$credentials.authToken}}',
		},
	},
};
```

* `qs`: Object. Stands for "query string." Send authentication data in the request query string.

```typescript
authenticate: IAuthenticateGeneric = {
	type: 'generic',
	properties: {
		qs: {
			token: '={{$credentials.token}}',
		},
	},
};
```

* `auth`: Object. Used for Basic Auth. Requires `username` and `password` as the key names.

```typescript
authenticate: IAuthenticateGeneric = {
	type: 'generic',
	properties: {
		auth: {
			username: '={{$credentials.username}}',
			password: '={{$credentials.password}}',
		},
	},
};
```

### `test` <a href="#test" id="test"></a>

Provide a `request` object containing a URL and authentication type that n8n can use to test the credential.

```typescript
test: ICredentialTestRequest = {
		request: {
			baseURL: '={{$credentials?.domain}}',
			url: '/bearer',
		},
	};
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.n8n.io/connect/create-nodes/build-your-node/reference/credentials-files.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
