# Fail over a Valkey instance

Switch the primary to a replica without losing written data, such as for a drill. A switchover needs a running primary and a running replica. Writes fail for about 20 seconds, until your client reconnects to the hostname.

[endpoint]
method = "POST"
base_url = "https://{availability_zone}.betterstackcloud.com"
path = "/v1/valkey/{id}/failover"

[[path_param]]
name = "id"
required = true
type = "string"
description = "The ID of the Valkey instance to failover."

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"
[/endpoint]

[responses]
[[response]]
status = 202
description = "Returns the Valkey instance."
body = '''
{
  "id": "example",
  "name": "Example Valkey instance",
  "type": "VK1",
  "usable_memory_gb": 1,
  "max_connections": 1,
  "engine_version": "1.4.2",
  "available_engine_versions": [
    "1.4.2"
  ],
  "status": "provisioning",
  "status_message": "example",
  "eviction_policy": "noeviction",
  "persistence": "rdb",
  "public_access": false,
  "replica_count": 50,
  "endpoint": {
    "hostname": "proxy.example.com",
    "public_hostname": "proxy.example.com",
    "port": 443,
    "tls_port": 443,
    "private_ips": [
      {
        "network_id": "123456789",
        "ip_address": "example"
      }
    ],
    "public_ips": [
      {
        "ip": "example",
        "type": "example"
      }
    ]
  },
  "members": [
    {
      "id": "example",
      "role": "primary",
      "status": "provisioning",
      "replication_lag_bytes": 1,
      "private_ips": [
        {
          "network_id": "123456789",
          "ip_address": "example"
        }
      ],
      "created_at": "2026-07-01T12:00:00.000Z"
    }
  ],
  "network_ids": [
    "123456789"
  ],
  "firewall_ids": [
    "123456789"
  ],
  "latest_snapshot_at": "2026-07-01T12:00:00.000Z",
  "term": "monthly",
  "created_at": "2026-07-01T12:00:00.000Z",
  "updated_at": "2026-07-01T12:00:00.000Z",
  "team_id": "t123",
  "metadata": {
    "example": "value"
  }
}
'''

[[response]]
status = 400
description = "The body isn't valid JSON."
body = '''
{
  "error": {
    "message": "Malformed JSON body.",
    "code": "bad_request"
  }
}
'''

[[response]]
status = 401
description = "The API token is missing or invalid."
body = '''
{
  "error": {
    "message": "Missing or invalid token.",
    "code": "unauthorized"
  }
}
'''

[[response]]
status = 402
description = "The organization hasn't made its first payment yet, and the request creates a resource we charge for. The code is `payment_required`. A request that creates a server, load balancer, object cache, database, reserved IP or volume can also return `first_purchase`. The `url` in `first_purchase` opens a page where you make the payment. The resource is created after the payment. The page works until `expires_at`, 24 hours after the response."
body = '''
{
  "error": {
    "message": "We require at least one successful credit card transaction before allowing billable actions via the API. This significantly helps us to prevent fraud. Once your first transaction is processed, you will be able to use the API unrestricted. Please add credit to your account at https://betterstack.com/settings/billing/card/new?credits=10&activate_api=true. Need help? We're here for you at hello@betterstack.com.",
    "code": "payment_required"
  }
}
'''

[[response]]
status = 403
description = "The request would go over a quota, with the code `quota_exceeded`. Or a read-only token tried to make a change, with the code `read_only_token`. Or a rule of the resource forbids it."
body = '''
{
  "error": {
    "message": "This token is read-only and cannot be used for write operations.",
    "code": "read_only_token"
  }
}
'''

[[response]]
status = 404
description = "The resource doesn't exist, it's in another zone, or your token can't access it."
body = '''
{
  "error": {
    "message": "Resource not found.",
    "code": "not_found"
  }
}
'''

[[response]]
status = 409
description = "The instance isn't `running` or `degraded`, with the code `valkey_busy`. Or it has no running primary and running replica, with the code `no_failover_target`."

[[response]]
status = 423
description = "We've locked the resource, with the code `locked`. Every change to a locked resource is refused, and so is a change that involves one."

[[response]]
status = 429
description = "Too many requests, with the code `rate_limited`. We limit requests per client IP and per organization, and some costly endpoints have a stricter limit. Wait as long as the `Retry-After` header says."

[[response]]
status = 500
description = "An unexpected, temporary error on our side, with the code `internal_error`. Try again."
body = '''
{
  "error": {
    "message": "The request could not be completed right now. Please try again in a few moments.",
    "code": "internal_error"
  }
}
'''

[[response]]
status = 503
description = "The zone has no capacity, with the code `no_capacity`. Or we couldn't set up or change the resource, with the code `orchestration_failed`. Or the organization is creating too many resources at the same time, with the code `concurrent_create_limit`. Try again after a short wait."
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "id"
type = "string"
description = "The instance's ID, a UUID."

[[param]]
name = "name"
type = "string"
description = "The instance's name, up to 255 characters."

[[param]]
name = "type"
type = "string"
description = "The plan, such as `VK2`."

[[param]]
name = "usable_memory_gb"
type = "integer"
description = "Memory for your data on each member, in GiB."

[[param]]
name = "max_connections"
type = "integer"
description = "The most client connections the plan accepts."

[[param]]
name = "engine_version"
type = "string"
description = "The Valkey version, such as `9.1`."

[[param]]
name = "available_engine_versions"
type = "array of strings"
description = "The versions you can upgrade the instance to now."

[[param]]
name = "status"
type = "string"
description = "The instance's state. A new instance is ready once it's `running`. A `running` instance can still be adding a replica or opening its public TLS endpoint.<br/>Valid values:<br/>`provisioning`: We're creating the instance.<br/>`running`: The instance is ready.<br/>`degraded`: A member doesn't respond. `status_message` says which.<br/>`rescaling`: We're changing the plan.<br/>`upgrading`: We're upgrading the Valkey version.<br/>`restoring`: We're restoring a snapshot onto the instance.<br/>`failed`: The instance couldn't be created and stays in this state.<br/>`destroyed`: The instance is deleted."

[[param]]
name = "status_message"
type = "string or null"
description = "What needs attention now, such as a member that doesn't respond or a rescale or upgrade that didn't complete. Is `null` when all is well."

[[param]]
name = "eviction_policy"
type = "string"
description = "What Valkey does when memory is full, as its `maxmemory-policy` setting.<br/>Valid values:<br/>`noeviction`: Valkey refuses writes when memory is full.<br/>`allkeys-lru`: Valkey evicts the least recently used keys.<br/>`allkeys-lfu`: Valkey evicts the least frequently used keys.<br/>`allkeys-random`: Valkey evicts random keys.<br/>`volatile-lru`: Valkey evicts the least recently used keys that have an expiry.<br/>`volatile-lfu`: Valkey evicts the least frequently used keys that have an expiry.<br/>`volatile-random`: Valkey evicts random keys that have an expiry.<br/>`volatile-ttl`: Valkey evicts the keys with an expiry that expire soonest."

[[param]]
name = "persistence"
type = "string"
description = "Whether Valkey keeps the data across restarts. Snapshots work either way.<br/>Valid values:<br/>`rdb`: Valkey keeps the data across restarts.<br/>`none`: Valkey keeps the data in memory only, as a pure cache."

[[param]]
name = "public_access"
type = "boolean"
description = "Whether the primary accepts connections with TLS on a public IP, on port 6380."

[[param]]
name = "replica_count"
type = "integer"
description = "How many replicas the instance has besides the primary, from 0 to 2."

[[param]]
name = "endpoint"
type = "object"
description = "Where to connect to the current primary."

[[param]]
name = "endpoint.hostname"
type = "string or null"
description = "The hostname to connect to from your private networks. Always points at the current primary's addresses in those networks."

[[param]]
name = "endpoint.public_hostname"
type = "string or null"
description = "The hostname to connect to from the internet, on the public TLS endpoint, or `null` when `public_access` is off. Always points at the current primary's public IP addresses."

[[param]]
name = "endpoint.port"
type = "integer"
description = "The port without TLS on private networks, `6379`."

[[param]]
name = "endpoint.tls_port"
type = "integer or null"
description = "The public TLS port, `6380`, or `null` when `public_access` is off."

[[param]]
name = "endpoint.private_ips"
type = "array of objects"
description = "The primary's addresses in the attached private networks."

[[param]]
name = "endpoint.private_ips[].network_id"
type = "string"
description = "The ID of the private network."

[[param]]
name = "endpoint.private_ips[].ip_address"
type = "string"
description = "The primary's IP address in that network."

[[param]]
name = "endpoint.public_ips"
type = "array of objects"
description = "The primary's public IP addresses, empty when `public_access` is off."

[[param]]
name = "endpoint.public_ips[].ip"
type = "string"
description = "The public IP address."

[[param]]
name = "endpoint.public_ips[].type"
type = "string"
description = "The address type, `ipv4` or `ipv6`."

[[param]]
name = "members"
type = "array of objects"
description = "The instance's primary and replicas, with their addresses in your private networks."

[[param]]
name = "members[].id"
type = "string"
description = "The member's ID."

[[param]]
name = "members[].role"
type = "string"
description = "The member's role.<br/>Valid values:<br/>`primary`: The member accepts writes.<br/>`replica`: The member copies the primary and serves reads."

[[param]]
name = "members[].status"
type = "string"
description = "The member's state. Send traffic to a member only while it's `running`.<br/>Valid values:<br/>`provisioning`: We're creating the member.<br/>`syncing`: The replica is copying the primary's data.<br/>`running`: The member serves traffic.<br/>`down`: The member doesn't respond."

[[param]]
name = "members[].replication_lag_bytes"
type = "integer or null"
description = "How far the replica is behind the primary, in bytes, or `null` for the primary."

[[param]]
name = "members[].private_ips"
type = "array of objects"
description = "The member's addresses in the attached private networks."

[[param]]
name = "members[].private_ips[].network_id"
type = "string"
description = "The ID of the private network."

[[param]]
name = "members[].private_ips[].ip_address"
type = "string"
description = "The member's IP address in that network."

[[param]]
name = "members[].created_at"
type = "datetime"
description = "When the member was created. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "network_ids"
type = "array of strings"
description = "The IDs of the private networks attached to the instance. Order doesn't matter."

[[param]]
name = "firewall_ids"
type = "array of strings"
description = "The IDs of the firewalls attached to the instance. An instance can have one firewall. Order doesn't matter."

[[param]]
name = "latest_snapshot_at"
type = "datetime or null"
description = "When the newest available snapshot was created. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "term"
type = "string"
description = "The billing term. Defaults to `monthly`.<br/>Valid values:<br/>`monthly`: The instance is billed every month.<br/>`annual`: The instance is paid for a year."

[[param]]
name = "created_at"
type = "datetime"
description = "When the instance was created. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "updated_at"
type = "datetime"
description = "When the instance was last changed. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "team_id"
type = "string"
description = "The ID of the team that owns the instance."

[[param]]
name = "metadata"
type = "object"
description = "Your own tags as string pairs, at most 10."
[/params]
