# Set a variable

> Page: https://docs.flung.dev/reference/api/put-v1-variables-name. Index of every page: https://docs.flung.dev/llms.txt

Set a variable.

`PUT /v1/variables/{name}`

## TL;DR

| Question | Answer |
|---|---|
| What does it do? | Set a variable. |
| What does it need? | An API key or an OAuth access token. |
| What does it take? | A JSON body with the fields below, and `name` in the path. |
| What does it return? | Status 200 with a body of type [`Variable`](https://docs.flung.dev/reference/api/schemas.md#variable). |
| In the SDK? | `flung.variables.set()` |
| As an MCP tool? | [`set_variable`](https://docs.flung.dev/reference/mcp/set-variable.md) |
| What can go wrong? | `401` Missing, unknown, revoked or expired API key; `422` The request failed validation; `429` Too many requests for this credential; wait for `retry-after` seconds. Every failure has the same [error shape](https://docs.flung.dev/reference/api/errors.md). |

## Example

**curl**

```bash
curl -X PUT 'https://api.flung.dev/v1/variables/string' \
  --header "Authorization: Bearer $FLUNG_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "value": "string"
}'
```

**TypeScript**

```ts
import { Flung } from '@flung.dev/sdk'

const flung = new Flung({ apiKey: process.env.FLUNG_API_KEY! })
const result = await flung.variables.set({
  name: 'string',
  value: 'string',
})
```

**fetch**

```js
const response = await fetch('https://api.flung.dev/v1/variables/string', {
  method: 'PUT',
  headers: {
    'Authorization': `Bearer ${process.env.FLUNG_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    value: 'string',
  }),
})
if (!response.ok) throw new Error((await response.json()).error.message)
const result = await response.json()
```

A successful answer looks like this:

```json
{
  "name": "string",
  "value": "string",
  "updatedAt": "2026-11-01T09:00:00.000Z"
}
```

## Path parameters

| Field | Type | Required | Description |
|---|---|---|---|
| `name` | `string` | yes |  |

## Request body

The body has the type an object, with the fields below.

| Field | Type | Required | Description |
|---|---|---|---|
| `value` | `string` | yes | at most 2000 characters. |

## Responses

| Status | Meaning | Body |
|---|---|---|
| 200 | The variable. | [`Variable`](https://docs.flung.dev/reference/api/schemas.md#variable) |
| 401 | Missing, unknown, revoked or expired API key. | [`Error`](https://docs.flung.dev/reference/api/schemas.md#error) |
| 422 | The request failed validation. | [`Error`](https://docs.flung.dev/reference/api/schemas.md#error) |
| 429 | Too many requests for this credential; wait for `retry-after` seconds. | [`Error`](https://docs.flung.dev/reference/api/schemas.md#error) |

## Response body

A 200 answer has the type [`Variable`](https://docs.flung.dev/reference/api/schemas.md#variable).

| Field | Type | Required | Description |
|---|---|---|---|
| `name` | `string` | yes |  |
| `value` | `string` | yes |  |
| `updatedAt` | `string` | yes |  |

## See also

| Doc | Why |
|---|---|
| [API reference](https://docs.flung.dev/reference/api.md) | Every endpoint |
| [Schemas](https://docs.flung.dev/reference/api/schemas.md) | Every request and response type |
| [Errors](https://docs.flung.dev/reference/api/errors.md) | Every error code and what to do about it |
| [`set_variable`](https://docs.flung.dev/reference/mcp/set-variable.md) | The same operation as an MCP tool |
