# General Translation Platform: setConfig
URL: https://generaltranslation.com/en-US/docs/platform/core/reference/gt-class/set-config.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Update configuration on an existing GT instance. API reference for setConfig.

Change the API credentials, locales, and other settings of a [GT](/docs/platform/core/reference/gt-class/constructor) instance after it was created, without constructing a new one.

## Overview [#overview]

Call `setConfig` to modify an instance in place. The new values merge with the configuration passed to the constructor and apply to every subsequent method call.

```typescript
const gt = new GT();

gt.setConfig({
  apiKey: 'your-new-api-key',
  projectId: 'your-project-id',
  sourceLocale: 'en',
  targetLocale: 'es',
});
```

Signature:

```typescript
setConfig(params: GTConstructorParams): void
```

*Note: `setConfig` is synchronous and returns `void`; it updates the instance in place.*

## How it works [#how-it-works]

- **Configured identities.** Locale spellings are preserved. All provided locale fields, including `locales`, validate against the effective custom mapping. Invalid codes throw. Returned locale codes follow the [constructor rules](/docs/platform/core/reference/gt-class/constructor#how-it-works).
- **Changing credentials.** Use this method to switch credentials or project settings. Direct property assignment is not supported for these changes.
- **Configuration merge.** New values merge with the configuration passed to the constructor. A `customMapping`, however, completely replaces any existing mapping rather than merging.
- **No environment re-read.** Environment variables (`GT_API_KEY`, `GT_DEV_API_KEY`, `GT_PROJECT_ID`) are not re-read when calling `setConfig`.
- **Failed updates.** If an update fails, some settings may already have changed.

## Parameters [#parameters]

`setConfig` accepts a required [`GTConstructorParams`](/docs/platform/core/reference/types/gt-constructor-params) object with the same properties as the [constructor](/docs/platform/core/reference/gt-class/constructor):

| Parameter | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| [`apiKey`](#api-key) | Project API key for the translation service. | `string` | Yes | — |
| [`devApiKey`](#dev-api-key) | Alternate project API key, used when `apiKey` is unset. | `string` | Yes | — |
| [`projectId`](#project-id) | Unique project identifier. | `string` | Yes | — |
| [`sourceLocale`](#source-locale) | Default source locale for translations. | `string` | Yes | — |
| [`targetLocale`](#target-locale) | Default target locale for translations. | `string` | Yes | — |
| [`locales`](#locales) | Supported locale codes. | `string[]` | Yes | — |
| [`baseUrl`](#base-url) | Custom API base URL. | `string` | Yes | — |
| [`customMapping`](#custom-mapping) | Custom locale code mappings and property overrides. | [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) | Yes | — |

The `params` object itself is required, though every property on it is optional — pass only the settings you want to change.

### `apiKey` [#api-key]

**Type** `string` · **Optional**

Project API key for the translation service.

### `devApiKey` [#dev-api-key]

**Type** `string` · **Optional**

Deprecated compatibility alias for `apiKey`. Used when `apiKey` is unset, regardless of environment.

### `projectId` [#project-id]

**Type** `string` · **Optional**

Unique project identifier.

### `sourceLocale` [#source-locale]

**Type** `string` · **Optional**

Default source locale for translations. Its spelling is preserved and validated with the effective `customMapping`, including aliases.

### `targetLocale` [#target-locale]

**Type** `string` · **Optional**

Default target locale for translations. Its spelling is preserved and validated with the effective `customMapping`, including aliases.

### `locales` [#locales]

**Type** `string[]` · **Optional**

Array of supported locale identities. Each code is preserved and validated with the effective `customMapping`; custom aliases are accepted.

### `baseUrl` [#base-url]

**Type** `string` · **Optional**

Custom API base URL.

### `customMapping` [#custom-mapping]

**Type** [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) · **Optional**

Custom locale code mappings and property overrides. Unlike the other settings, a new `customMapping` completely replaces the existing mapping instead of merging.

## Returns [#returns]

**Type** `void`

The method updates the instance configuration in place and returns nothing.

## Examples [#examples]

```typescript
const gt = new GT({
  sourceLocale: 'en',
  targetLocale: 'es',
});

// Switch the target locale from Spanish to French
gt.setConfig({
  targetLocale: 'fr',
});
```

## Notes [#notes]

- Configuration changes take effect immediately for subsequent method calls.
- Configured locale identities are preserved and validated with the effective custom mapping, including entries in `locales`.
- Empty strings or `undefined` do not clear credentials.
- Environment variables are not re-read when calling `setConfig`.
- Custom mappings completely replace existing mappings (they are not merged).
- If an update fails, some settings may already have changed.
- The method is synchronous and returns `void`.

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
