# llCreateKeyValue

*LSL function (requires an experience)*

```lsl
key key llCreateKeyValue(string k, string v);
```

- `string k`: Unique key name for the key-value pair.
- `string v`: Value for the key-value pair (maximum 2047 characters, or 4095 characters if using Mono).

- Returns: `key`
- Energy: 10

Start an asynchronous transaction to create a key-value pair associated with the script's [Experience](/categories/experience/) using the given key (**k**) and value (**v**).

If the key already exists the [dataserver](/events/dataserver/) will return a failure along with the error [XP_ERROR_STORAGE_EXCEPTION](/constants/XP_ERROR_STORAGE_EXCEPTION/).

As of Jan 1, 2016 maximum bytes is 1011 for key and 4095 for value for both LSO and Mono scripts.

Returns a [key](https://wiki.secondlife.com/wiki/key) that can be used to identify the corresponding [dataserver](/events/dataserver/) event to determine if this command succeeded or failed.

```lsl title="How to use" frame="terminal"
key result = llCreateKeyValue("", "");
```

## Caveats

- It is recommended that keys do not contain commas due to [llKeysKeyValue](/functions/llKeysKeyValue/) returning keys in CSV format.

## Examples

<details open>
<summary>Example 1</summary>

```lsl collapse={18-30}
key trans;
default
{
    touch_start(integer total_number)
    {
        trans = llCreateKeyValue("FOO", "BAR");
    }

    dataserver(key t, string value)
    {
        if (t == trans)
        {
            // our llCreateKeyValue transaction is done
            integer result = (integer)llGetSubString(value, 0, 0);
            if (result == 1)
            {
                // the key-value pair was successfully created
                llSay(0, "New key-value pair was created");
            }
            else
            {
                // the key-value pair was not created
                integer error = (integer)(llGetSubString(value, 2, -1));
                llSay(0, "Key-value failed to create: " + llGetExperienceErrorMessage(error));
            }
        }
    }
}
```

</details>

## See also

### Functions

- [llGetExperienceErrorMessage](/functions/llGetExperienceErrorMessage/)
- [llReadKeyValue](/functions/llReadKeyValue/)
- [llUpdateKeyValue](/functions/llUpdateKeyValue/)
- [llDeleteKeyValue](/functions/llDeleteKeyValue/)
- [llDataSizeKeyValue](/functions/llDataSizeKeyValue/)
- [llKeyCountKeyValue](/functions/llKeyCountKeyValue/)
- [llKeysKeyValue](/functions/llKeysKeyValue/)

---

*Source: [LlCreateKeyValue](https://wiki.secondlife.com/wiki/LlCreateKeyValue) on the Second Life Wiki. Content from the Second Life Wiki articles LlCreateKeyValue (revision 1210585, 2022-04-06), Template:LSL Function/KeyValue (revision 1218517, 2025-11-17) and Template:LSL Function/Experience (revision 1210521, 2022-03-11), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/functions/llCreateKeyValue/
