> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paubox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# SDK authentication

> Configure Paubox API credentials for the C# SDK with a constructor parameter or IConfiguration in ASP.NET Core, plus Forms client setup and security notes.

## Obtain your API key

The Email API client requires a single credential:

* **API key**: a secret token that authenticates your requests

It is available in the [Paubox dashboard](https://next.paubox.com) under **API Credentials**.

## Option 1: Constructor parameter

Pass your API key directly; useful for console apps or when managing secrets via environment variables:

```csharp theme={null}
var emailLib = new EmailLibrary("YOUR_API_KEY");
```

Read from an environment variable:

```csharp theme={null}
var emailLib = new EmailLibrary(
    Environment.GetEnvironmentVariable("PAUBOX_API_KEY")
);
```

## Option 2: IConfiguration (recommended for ASP.NET Core)

Add your API key to `appsettings.json`:

```json theme={null}
{
  "APIKey": "YOUR_API_KEY"
}
```

Then inject `IConfiguration` and pass it to the constructor:

```csharp theme={null}
// In Program.cs or Startup.cs
builder.Services.AddSingleton<IEmailLibrary>(sp =>
{
    var config = sp.GetRequiredService<IConfiguration>();
    return new EmailLibrary(config);
});
```

Or instantiate directly:

```csharp theme={null}
var emailLib = new EmailLibrary(configuration);
```

The SDK reads `APIKey` from the configuration and sets the `Authorization` header automatically on every request:

```
Authorization: Token token=YOUR_API_KEY
```

## Forms client

`FormsLibrary` requires no credentials. Instantiate it with no arguments:

```csharp theme={null}
var formsLib = new FormsLibrary();
```

Use `IFormsLibrary` in ASP.NET Core for dependency injection and testability:

```csharp theme={null}
builder.Services.AddSingleton<IFormsLibrary, FormsLibrary>();
```

## Security notes

* Never hard-code credentials in source files. Use `appsettings.json` with user secrets or environment variables.
* Use [.NET user secrets](https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets) during development to keep credentials out of source control.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.