Integrate Semantic Cache with OpenClaw

Updated at:

This topic describes how to integrate the Tair Semantic Cache gateway (OpenAI-compatible mode) with OpenClaw Agent to achieve millisecond-level responses for AI conversations in semantically similar scenarios. The entire procedure takes approximately 3 minutes.

Prerequisites

Prerequisite

Description

Semantic Cache instance

A Semantic Cache instance is created and in the Running state. If you have not created one, see Semantic cache instance setup.

Connection information

The service address (Base URL) and API key are obtained.

OpenClaw

OpenClaw is installed and can communicate with LLMs.

Step 1: Obtain the Semantic Cache connection information

  1. Log on to the Tair console. In the left-side navigation pane, click Tair Semantic Cache Gateway Instance.

  2. In the instance list, click the name of the target instance to go to the instance details page.

  3. In the Access Information section, obtain the following information:

    Item

    Description

    Example

    Endpoint / Base URL

    Used to replace the model service address in OpenClaw.

    https://tg-bp1******.redis.rds.aliyuncs.com

    API Key

    Used for authentication.

    sk-****

Note

If you want to access the instance over the Internet, such as from a local development machine, click the Request button next to Public Access in the Network Access section. After the application is approved, the Base URL changes to a public endpoint. The API key remains unchanged. Select the address that matches your network environment.

Step 2: Modify the OpenClaw provider configuration

The OpenClaw configuration file must be edited by using a terminal (command line).

Open a terminal:

  • macOS: Press Command + Space to open Spotlight Search, type Terminal, and press Enter.

  • Windows: Press Win + R, type cmd or powershell, and press Enter.

Locate the configuration file:

The OpenClaw configuration file is typically located in the installation directory and named openclaw.json. The installation path may vary by user. Run the following command to find it:

openclaw config file

This command returns the full path of the configuration file. Example:

  • macOS/Linux: ~/.openclaw/openclaw.json

  • Windows: C:\Users\<username>\.openclaw\openclaw.json

  1. Open the configuration file in the terminal. Replace the path with the actual path obtained in the previous step.

    vim ~/.openclaw/openclaw.json
  2. In models.providers, find the target provider or add a new one. Replace baseUrl and apiKey with the connection information of the Semantic Cache instance:

    {
      "models": {
        "providers": {
          "bailian": {
            "baseUrl": "https://tg-xxxxxx.redis.rds.aliyuncs.com/compatible-mode/v1",
            "apiKey": "sk-xxxxxx",
            "api": "openai-completions",
            "models": [
              { "id": "qwen3.6-plus" }
            ]
          }
        }
      }
    }

Parameter description:

Parameter

Description

baseUrl

The service address of the Semantic Cache instance. You must append the /compatible-mode/v1 path.

apiKey

The API key of the Semantic Cache instance, not the API key of Model Studio.

api

Set to openai-completions. This indicates that the OpenAI-compatible protocol is used.

models.id

During the public preview, only qwen3.6-plus is supported.

Step 3: Restart OpenClaw Gateway

After you modify the configuration, run the following command to restart the gateway for the changes to take effect:

openclaw gateway restart

Verify the cache

Verify by using OpenClaw conversations

  1. In OpenClaw, send a question, such as What is Redis Cluster?

  2. Wait for the response. The first request calls the LLM and takes longer to respond, typically tens of seconds.

  3. Send a semantically similar question with a different wording, such as Explain Redis Cluster.

  4. Observe the response speed. If the cache is hit, the second response is completed within milliseconds, and the response content is the same as the first one.

Verify by using curl

You can also bypass OpenClaw and send requests directly to the Semantic Cache instance to verify the cache.

First request (write to cache):

curl "https://<Base URL>/compatible-mode/v1/chat/completions" \
  -H "Authorization: Bearer <API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.6-plus",
    "messages": [{"role": "user", "content": "What is Redis Cluster"}]
  }'

Second request (verify cache hit):

curl "https://<Base URL>/compatible-mode/v1/chat/completions" \
  -H "Authorization: Bearer <API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.6-plus",
    "messages": [{"role": "user", "content": "Explain Redis Cluster"}]
  }'

If the cache is hit, the response time of the second request is reduced from tens of seconds to milliseconds.

Usage notes

Item

Description

Public and internal endpoints

The public endpoint and internal endpoint are different. Make sure that you use the endpoint that matches your network environment. The API key is not affected.

Model support

During the public preview, only qwen3.6-plus is supported for the model parameter.

Configuration activation

After you modify the provider configuration, we recommend that you run openclaw gateway restart to make sure the changes take effect.

Cache matching scope

Semantic Cache extracts the last user message for matching by default. If the request contains complex multi-turn conversation history, the matching behavior may differ from your expectations.

Related operations

  • Adjust the similarity threshold: A lower threshold increases the hit rate but may cause false matches. A higher threshold improves precision but reduces the hit rate. You can adjust this value in the plug-in configuration on the console. The default value is 0.85.

  • Configure the cache TTL: Set an appropriate TTL for scenarios where cached responses may become outdated.

  • Configure the index field (index_from): By setting the index field, you can filter cache data and implement multi-tenant isolation. Cache data with different index values is isolated and does not interfere with each other.

  • View the complete API capabilities: See Technical architecture and API.