LaunchDarkly Contexts API

Contexts are people, services, machines, or other resources that encounter feature flags in your product. Contexts are identified by their `kind`, which describes the type of resources encountering flags, and by their `key`. Each unique combination of one or more contexts that have encountered a feature flag in your product is called a context instance. When you use the LaunchDarkly SDK to evaluate a flag, you provide a context to that call. LaunchDarkly records the key and attributes of each context. You can view these in the LaunchDarkly user interface from the **Contexts** list, or use the Context APIs. To learn more, read [Contexts](https://launchdarkly.com/docs/home/observability/contexts). LaunchDarkly provides APIs for you to: * retrieve contexts and context attribute names and values * search for contexts * fetch context kinds * create and update context kinds To learn more about context kinds, read [Context kinds](https://launchdarkly.com/docs/home/observability/context-kinds). Contexts are always scoped within a project and an environment. Each environment has its own set of context records. Context records reflect the contexts that LaunchDarkly has received within the last 30 days. Some of the endpoints in the contexts API accept an application ID. The application ID is returned as the `applicationId` field of each element in the `items` array of the [Get contexts](https://launchdarkly.com/docs/api/contexts/get-contexts) response. By default, the application ID is set to the SDK you are using. In the LaunchDarkly UI, the application ID and application version appear on the context details page in the "From source" field. You can change the application ID as part of your SDK configuration. To learn more, read [Application metadata configuration](https://launchdarkly.com/docs/sdk/features/app-config). ### Filtering contexts When you [search for contexts](https://launchdarkly.com/docs/api/contexts/search-contexts), you can filter the results using fields and operators with the `filter` parameter. Specify `filter` either as a query parameter or as a request body parameter. The `filter` parameter supports the following operators: `after`, `anyOf`, `before`, `contains`, `equals`, `exists`, `notEquals`, `startsWith`. Expand for details on operators and syntax #### after Returns contexts if the field's date value occurs after the specified time. Provide an RFC 3339 timestamp or Unix epoch milliseconds. For example: * `myField after "2022-09-21T19:03:15+00:00"` #### anyOf Returns contexts if the field value matches any of the provided values. The `anyOf` operator is supported for the `applicationId`, `key`, `kind`, `kindKey`, `kindKeys`, and `kinds` fields only. To match an attribute against multiple values, use `equals` with an array value instead. For example: * `kind anyOf ["user","device"]` * `key anyOf ["user-key-123abc","user-key-456def"]` #### before Returns contexts if the field's date value occurs before the provided time. Provide an RFC 3339 timestamp or Unix epoch milliseconds. For example: * `myField before "2022-09-21T19:03:15+00:00"` #### contains Returns contexts whose kind or kind and key match the provided value. The `contains` operator is supported for the `kinds` and `kindKeys` fields only, and accepts exactly one value. For example: * `kinds contains ["user"]` * `kindKeys contains ["user:user-key-123abc"]` #### equals Returns contexts only if the field value exactly matches the provided value. If you provide an array, the filter matches if the field value equals any element of the array. For example: * `myField equals 44` * `myField equals "device"` * `myField equals true` * `myField equals [1,2,3,4]` * `myField equals ["hello","goodbye"]` #### exists Returns contexts based on whether the specified field exists. The `exists` operator is supported for the `name` field and attribute fields only. For example: * `myField exists true` * `myField exists false` * `*.name exists true` #### notEquals Returns contexts if the field value does not exactly match the provided value. If you provide an array, the filter matches if the field value does not equal any element of the array. For example: * `myField notEquals 44` * `myField notEquals "device"` * `myField notEquals true` * `myField notEquals [1,2,3,4]` * `myField notEquals ["hello","goodbye"]` #### startsWith Returns contexts if a singular string field value begins with the provided substring. The substring can be at most 500 characters. Matching is case-sensitive. For example: * `myField startsWith "do"` You can also combine filters in the following ways: * Use a comma (`,`) as an AND operator * Use a vertical bar (`|`) as an OR operator * Use parentheses `()` to group filters For example: * `myField notEquals 0, myField notEquals 1` returns contexts where `myField` is not 0 and is not 1 * `myFirstField equals "device",(mySecondField equals "iPhone"|mySecondField equals "iPad")` returns contexts where `myFirstField` is equal to "device" and `mySecondField` is equal to either "iPhone" or "iPad" #### Supported fields and operators You can only filter some fields using certain operators. When you search for [contexts](https://launchdarkly.com/docs/api/contexts/search-contexts), the `filter` parameter supports the following fields and operators: |Field |Description |Supported operators | |---|---|---| |`applicationId` |An identifier that represents the application where the LaunchDarkly SDK is running. |`equals`, `notEquals`, `anyOf`, `startsWith` | |`key` |The context key. |`equals`, `notEquals`, `anyOf`, `startsWith` | |`kind` |The context kind. |`equals`, `notEquals`, `anyOf`, `startsWith` | |`kinds` |The context's kind. Supply a list of strings to the operator. The filter matches contexts whose kind is any of the provided values. The `contains` operator accepts exactly one value. |`equals`, `anyOf`, `contains` | |`kindKey` |The kind and key for the context, joined with a `:`. For example, `user:user-key-abc123`. |`equals`, `notEquals`, `anyOf` | |`kindKeys` |The kind and key for the context, joined with a `:`. For example, `user:user-key-abc123`. Supply a list of strings to the operator. The filter matches contexts whose kind and key match any of the provided values. The `contains` operator accepts exactly one value. |`equals`, `anyOf`, `contains` | |`q` |A prefix search across the context key and the `name`, `firstName`, `lastName`, and `email` attributes. Supply a single string to the operator. |`equals` | |`name` |The name for the context. |`equals`, `notEquals`, `exists`, `startsWith` | |`.` |A kind and the name of any attribute that appears in a context of that kind, for example, `user.email`. To filter all kinds use `*` in place of the kind. For example, `*.email`. Reference a nested attribute by joining path segments with periods. For example, `user.address.city` filters on the `city` field within the `address` attribute of a user context. Each path segment may contain letters, numbers, underscores, and hyphens, and may not start with a number. JSON pointer escaping (`~0`, `~1`) is not supported. If the value includes whitespace, enclose it in double quotes. A filter may include at most 10 attribute clauses. |`equals`, `notEquals`, `exists`, `startsWith`, `before`, `after`.|

Operations 7

GET /api/v2/projects/{projectKey}/context-kinds Get context kinds #
PUT /api/v2/projects/{projectKey}/context-kinds/{key} Create or update context kind #
GET /api/v2/projects/{projectKey}/environments/{environmentKey}/context-attributes Get context attribute names #
GET /api/v2/projects/{projectKey}/environments/{environmentKey}/context-attributes/{attributeName} Get context attribute values #
POST /api/v2/projects/{projectKey}/environments/{environmentKey}/contexts/search Search for contexts #
GET /api/v2/projects/{projectKey}/environments/{environmentKey}/contexts/{kind}/{key} Get contexts #
POST /api/v2/projects/{projectKey}/environments/{environmentKey}/flags/evaluate Evaluate flags for context instance #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/launchdarkly:launchdarkly-contexts-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Discovery needs no key. Ratings and market analysis are Pro.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

launchdarkly-contexts-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: LaunchDarkly REST Contexts API
  description: 'This documentation describes LaunchDarkly''s REST API. To access the complete OpenAPI spec directly, use Get OpenAPI spec. To learn how to use LaunchDarkly using the user interface (UI) instead, read our product documentation. ## Authentication


    LaunchDarkly''s REST API uses the HTTPS protocol with a minimum TLS version of 1.2. All REST API resources are authenticated with either personal or service access tokens, or session cookies. Other authentication mechanisms are not supported. You can manage personal access tokens on your **Authorization** page in the LaunchDarkly UI. LaunchDarkly also has SDK keys, mobile keys, and client-side IDs that are used by our server-side SDKs, mobile SDKs, and JavaScript-based SDKs, respectively. **These keys cannot be used to access our REST API**. These keys are environment-specific, and can only perform read-only operations such as fetching feature flag settings. | Auth mechanism | Allowed resources | Use cases |

    | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------- |

    | Personal or service access tokens | Can be customized on a per-token basis | Building scripts, custom integrations, data export. |

    | SDK keys | Can only access read-only resources specific to server-side SDKs. Restricted to a single environment. | Server-side SDKs |

    | Mobile keys | Can only access read-only resources specific to mobile SDKs, and only for flags marked available to mobile keys. Restricted to a single environment. | Mobile SDKs |

    | Client-side ID | Can only access read-only resources specific to JavaScript-based client-side SDKs, and only for flags marked available to client-side. Restricted to a single environment. | Client-side JavaScript |


    > #### Keep your access tokens and SDK keys private

    >

    > Access tokens should _never_ be exposed in untrusted contexts. Never put an access token in client-side JavaScript, or embed it in a mobile application. LaunchDarkly has special mobile keys that you can embed in mobile apps. If you accidentally expose an access token or SDK key, you can reset it from your **Authorization** page. >

    > The client-side ID is safe to embed in untrusted contexts. It''s designed for use in client-side JavaScript. ### Authentication using request header


    The preferred way to authenticate with the API is by adding an `Authorization` header containing your access token to your requests. The value of the `Authorization` header must be your access token. Manage personal access tokens from the **Authorization** page. ### Authentication using session cookie


    For testing purposes, you can make API calls directly from your web browser. If you are logged in to the LaunchDarkly application, the API will use your existing session to authenticate calls. Depending on the permissions granted as part of your role, you may not have permission to perform some API calls. You will receive a `401` response code in that case. > ### Modifying the Origin header causes an error

    >

    > LaunchDarkly validates that the Origin header for any API request authenticated by a session cookie matches the expected Origin header. The expected Origin header is `https://app.launchdarkly.com`. >

    > If the Origin header does not match what''s expected, LaunchDarkly returns an error. This error can prevent the LaunchDarkly app from working correctly. >

    > Any browser extension that intentionally changes the Origin header can cause this problem. For example, Cross-Origin Resource Sharing (CORS) extensions used during development can modify the Origin header and cause the app to fail. >

    > To prevent this error, do not modify your Origin header. >

    > LaunchDarkly does not require origin matching when authenticating with an access token, so this issue does not affect normal API usage.'
  contact:
    name: LaunchDarkly Technical Support Team
    url: https://support.launchdarkly.com
    email: support@launchdarkly.com
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
  version: '2.0'
servers:
- url: https://app.launchdarkly.com
  description: ' Default'
- url: https://app.launchdarkly.us
  description: ' Federal'
security:
- ApiKey:
  - read
  - write
tags:


# --- truncated at 32 KB (52 KB total) ---
# Full source: https://raw.githubusercontent.com/api-evangelist/launchdarkly/refs/heads/main/openapi/launchdarkly-contexts-api-openapi.yml