We build custom applications 5x faster and cheaper 🚀
Book a Free Consultation
Stuck on an error? Book a 30-minute call with an engineer and get a direct fix + next steps. No pressure, no commitment.
The direct answer: build a small, authenticated, external search adapter (a proxy/microservice) that holds your Baidu credentials and provides a stable, authenticated REST API that an OpenClaw skill (configured in ClawHub) can call. Keep credentials and scopes in ClawHub secrets/environment variables, call the adapter from the skill runtime, and move caching, rate‑limit handling, pagination, and persistent indexing outside the agent runtime. Authenticate and validate every request, log and inspect API responses when things fail, and treat the agent as the thin orchestrator that invokes your external service — not the place for long-lived state or secret storage.
Use this as a starting point. Replace BAIDU_API_URL and BAIDU_API_KEY with values from Baidu docs. Store them in your deployment environment; do not commit them.
<b>//</b> server.js - minimal adapter that forwards to Baidu and normalizes results
const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.json());
const BAIDU_API_URL = process.env.BAIDU_API_URL; <b>//</b> e.g. https://api.baidu.com/xxx (replace with Baidu doc URL)
const BAIDU_API_KEY = process.env.BAIDU_API_KEY;
const ADAPTER_TOKEN = process.env.ADAPTER_TOKEN; <b>//</b> token the OpenClaw skill will present
if (!BAIDU_API_URL || !BAIDU_API_KEY || !ADAPTER_TOKEN) {
console.error('Missing required env vars: BAIDU_API_URL, BAIDU_API_KEY, ADAPTER_TOKEN');
process.exit(1);
}
app.get('/search', async (req, res) => {
try {
const authHeader = req.header('Authorization') || '';
if (authHeader !== `Bearer ${ADAPTER_TOKEN}`) {
return res.status(401).json({ error: 'unauthorized' });
}
const q = (req.query.q || '').trim();
if (!q) return res.status(400).json({ error: 'missing query param q' });
<b>//</b> Forward request to Baidu API. Adjust params/headers per Baidu docs.
const resp = await axios.get(BAIDU_API_URL, {
params: {
q,
// add other params required by Baidu: page, size, safe, etc.
// key: BAIDU_API_KEY // some APIs accept key param instead of header
},
headers: {
'Ocp-Apim-Subscription-Key': BAIDU_API_KEY <b>//</b> or correct header per Baidu docs
},
timeout: 5000
});
<b>//</b> Normalize response shape for the skill
const baiduData = resp.data;
const normalized = {
query: q,
raw: baiduData,
results: (baiduData.items || baiduData.results || []).map(item => ({
title: item.title || item.h1 || '',
snippet: item.snippet || item.summary || '',
url: item.url || item.link || ''
}))
};
res.json(normalized);
} catch (err) {
console.error('Adapter error', err.response ? err.response.data : err.message);
const status = err.response ? err.response.status : 500;
res.status(status).json({ error: 'search_error', details: err.response ? err.response.data : err.message });
}
});
const port = process.env.PORT || 8080;
app.listen(port, () => console.log(`Adapter listening on ${port}`));
This is a skill runtime snippet that calls your adapter. Store ADAPTER_URL and ADAPTER_TOKEN as ClawHub environment variables/secrets.
<b>//</b> skill-handler.js - run inside the OpenClaw skill runtime
async function handleSearchRequest(userQuery) {
const adapterUrl = process.env.ADAPTER_URL; <b>//</b> e.g. https://your-adapter.example.com/search
const token = process.env.ADAPTER_TOKEN;
if (!userQuery) {
return { error: 'no query provided' };
}
const url = `${adapterUrl}?q=${encodeURIComponent(userQuery)}`;
const resp = await fetch(url, {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`,
'Accept': 'application/json'
}
});
if (!resp.ok) {
const body = await resp.text();
throw new Error(`Adapter returned ${resp.status}: ${body}`);
}
const data = await resp.json();
<b>//</b> Return normalized results to the agent or user
return {
query: data.query,
results: data.results
};
}
Speak one‑on‑one with a senior engineer about your no‑code app, migration goals, and budget. In just half an hour you’ll leave with clear, actionable next steps—no strings attached.
1
Fetch the page as raw bytes and decode with a GBK/GB2312 codec (e.g. iconv‑lite in Node or .decode('gbk') in Python). Don’t rely only on headers—inspect the HTML meta charset or run a charset detector if needed.
// npm install iconv-lite
import iconv from 'iconv-lite';
async function fetchBaidu(url) {
const res = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
const ab = await res.arrayBuffer();
const buf = Buffer.from(ab);
// decode as GBK (gb2312 maps to gbk)
return iconv.decode(buf, 'gbk');
}
2
Yes — build skills in ClawHub, run agents in the OpenClaw runtime, and connect external services by calling real APIs (REST/GraphQL/SDKs) with credentials stored in environment variables or OAuth tokens; validate webhooks, inspect logs and skill traces, and move stateful or scaling pieces (databases, queues) outside the agent runtime for production.
const token = process.env.API_TOKEN; // read token
await fetch('https://api.example.com/data',{ // call API
headers:{ Authorization:`Bearer ${token}` }
});
3
To enable headless JS rendering, run a headless browser (Playwright/Puppeteer) as an external service and point your OpenClaw skill to it via environment variables or skill configuration in ClawHub; update selectors to be resilient (data-* attributes, ARIA, stable classes) and add waits for network/DOM stability before scraping.
Run a standalone headless renderer outside the agent runtime (container or service). Expose an HTTP/JSON endpoint (Playwright/Puppeteer server). Configure the skill in ClawHub or via env vars with that endpoint and auth token. Ensure skills request rendering, handle timeouts, and validate webhook/response integrity.
4
Set your Baidu credentials as environment variables (for example BAIDU_API_KEY/BAIDU_SECRET_KEY or BAIDU_APPID/BAIDU_SECRET_KEY). Obtain an access_token from Baidu’s OAuth endpoint for services that require it, and for Baidu Translate compute a sign = MD5(appid + q + salt + secret_key). Include either access_token (query/body) or sign/salt in the request, use UTF-8, and protect keys in your runtime (env vars or secret store).
Steps:
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
From startups to enterprises and everything in between, see for yourself our incredible impact.
Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.Â