# Does anyone try to use Perplexity API on Openclaw? Couldn't do it

**URL:** <https://community.perplexity.ai/t/does-anyone-try-to-use-perplexity-api-on-openclaw-couldnt-do-it/4760>\
**Category:** General\
**Tags:** agent-api\
**Created:** [April 9, 2026, 9:28am UTC](https://community.perplexity.ai/t/does-anyone-try-to-use-perplexity-api-on-openclaw-couldnt-do-it/4760 "2026-04-09T09:28:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonideo](https://sea1.discourse-cdn.com/flex001/user_avatar/community.perplexity.ai/leonideo/32/2238_2.png) [@leonideo](https://community.perplexity.ai/u/leonideo)\
**Post date:** [April 9, 2026, 9:28am UTC](https://community.perplexity.ai/t/does-anyone-try-to-use-perplexity-api-on-openclaw-couldnt-do-it/4760/1 "2026-04-09T09:28:32Z")

</div>

I have try many time’s and different ways even with perplexity computer but it doesnt works at all… Mabe anyone do it already and have some setup tips for me

---

<div class="post-metadata">

**Author:** ![Kesku](https://sea1.discourse-cdn.com/flex001/user_avatar/community.perplexity.ai/kesku/32/898_2.png) [@Kesku](https://community.perplexity.ai/u/Kesku)\
**Post date:** [April 9, 2026, 10:57pm UTC](https://community.perplexity.ai/t/does-anyone-try-to-use-perplexity-api-on-openclaw-couldnt-do-it/4760/2 "2026-04-09T22:57:13Z")

</div>

Hey! Have you read [Perplexity with OpenClaw - Perplexity](https://docs.perplexity.ai/docs/getting-started/integrations/openclaw)?

---

<div class="post-metadata">

**Author:** ![leonideo](https://sea1.discourse-cdn.com/flex001/user_avatar/community.perplexity.ai/leonideo/32/2238_2.png) [@leonideo](https://community.perplexity.ai/u/leonideo)\
**Post date:** [April 9, 2026, 11:28pm UTC](https://community.perplexity.ai/t/does-anyone-try-to-use-perplexity-api-on-openclaw-couldnt-do-it/4760/3 "2026-04-09T23:28:57Z")

</div>

Yeah i see about search but i mean use as LLM model but have a problem, gpts does work at all, sonar same, claude works but only chat mode tools doesn’t work

---

<div class="post-metadata">

**Author:** ![leonideo](https://sea1.discourse-cdn.com/flex001/user_avatar/community.perplexity.ai/leonideo/32/2238_2.png) [@leonideo](https://community.perplexity.ai/u/leonideo)\
**Post date:** [April 10, 2026, 3:12am UTC](https://community.perplexity.ai/t/does-anyone-try-to-use-perplexity-api-on-openclaw-couldnt-do-it/4760/4 "2026-04-10T03:12:22Z")

</div>

# **[FIX] OpenClaw + Perplexity Agent API: all tool calls fail with empty arguments `{}`**

**OpenClaw version:** 2026.4.9  
**Provider:** Perplexity Agent API (`https://api.perplexity.ai/v1`)  
**API type:** `openai-responses`  
**Model:** `perplexity/anthropic/claude-sonnet-4-6`

* * *

## **Symptom**

When using OpenClaw with the Perplexity Agent API in `openai-responses` mode, any tool (exec, write, read, etc.) fails with a validation error:

```auto
text

```

\*\*`Validation failed for tool "exec":`  
` - command: must have required property 'command'`

`Received arguments:`  
`{}`\*\*

Chat replies without tool calls work fine — only tool calling is broken. Arguments always come through as empty `{}`.

* * *

## **Cause**

The streaming parser for the OpenAI Responses API (`openai-responses-shared.js` from `@mariozechner/pi-ai`) expects function call arguments to arrive incrementally via `response.function_call_arguments.delta` events.  
However, **Perplexity Agent API sends all arguments immediately** in the first `response.output_item.added` event (inside `item.arguments`) and never emits subsequent `delta` or `done` events for function arguments.

Here’s what happens step by step:

1. On receiving `response.output_item.added` with `item.type === "function_call"`, the parser creates a `currentBlock` with `arguments: {}` and stores `item.arguments` in `partialJson`.

2. It then waits for `response.function_call_arguments.delta` events to fill `arguments` from `partialJson` — but **Perplexity never sends those**.

3. When `response.output_item.done` comes, the parser creates a **new** `toolCall` object with correctly parsed arguments from `partialJson` and passes it in the stream event `toolcall_end`, but **does not update** the existing entry in `output.content`.

4. The agent loop (`agent-loop.js` in `@mariozechner/pi-agent-core`) reads tool calls from `message.content` — where `arguments` are still `{}`.

5. Validation fails since required properties are missing.

Example from the session file:

```auto
json

```

**`{`  
 ` "type": "toolCall",`  
 ` "name": "exec",`  
 ` "arguments": {},`  
 ` "partialJson": "{\\"command\\": \\"echo \\\\\\"tools test ok\\\\\\"\\"}"`  
 `}`**

The arguments were correctly captured in `partialJson`, but never copied to `arguments`.

* * *

## **Fix**

## **File to patch**

```auto
text

```

**`/usr/lib/node_modules/openclaw/node_modules/@mariozechner/pi-ai/dist/providers/openai-responses-shared.js`**

## **What to change**

Find the `response.output_item.done` handler for type `function_call` (around lines 392–405). It looks like this:

```auto
javascript

```

**`else if (item.type === "function_call") {`  
 ` const args = currentBlock?.type === "toolCall" && currentBlock.partialJson`  
 ` ? parseStreamingJson(currentBlock.partialJson)`  
 ` : parseStreamingJson(item.arguments || "{}");`  
 ` const toolCall = {`  
 ` type: "toolCall",`  
 ` id: `${item.call_id}|${item.id}`,`  
 ` name: item.name,`  
 ` arguments: args,`  
 ` };`  
 ` currentBlock = null;`  
 ` stream.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });`  
 `}`**

Add two lines **before** `currentBlock = null;`:

```auto
javascript

```

**`else if (item.type === "function_call") {`  
 ` const args = currentBlock?.type === "toolCall" && currentBlock.partialJson`  
 ` ? parseStreamingJson(currentBlock.partialJson)`  
 ` : parseStreamingJson(item.arguments || "{}");`  
 ` const toolCall = {`  
 ` type: "toolCall",`  
 ` id: `${item.call_id}|${item.id}`,`  
 ` name: item.name,`  
 ` arguments: args,`  
 ` };`**  
_ **`// FIX: update entry in output.content so agent-loop sees correct arguments`** _\*\*  
` const idx = output.content.indexOf(currentBlock);`  
` if (idx >= 0) { output.content[idx] = toolCall; }`  
` currentBlock = null;`  
` stream.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });`  
`}`\*\*

## **Restart gateway**

After saving the file, restart the gateway service:

```auto
bash

```

**`systemctl --user restart openclaw-gateway`**

## **Why it works**

The `toolcall_end` event already contains the correct `toolCall` object with parsed arguments.  
The problem is that the agent loop reads tool calls from `message.content`, which still holds the old `currentBlock` with empty `{}` arguments.  
The patch replaces that outdated record with the properly parsed `toolCall` before clearing `currentBlock`.

* * *

## **Warning about updates**

This patch modifies a file inside `node_modules`.  
Whenever OpenClaw is updated (`npm update -g openclaw`), the patch will be overwritten — you’ll need to reapply it until it’s merged upstream in `@mariozechner/pi-ai`.

* * *

## **Extra: proper configuration for Perplexity Agent API**

Configuration file: `~/.openclaw/openclaw.json`

| **Parameter** | **Correct value** | **Common mistake** |
| --- | --- | --- |
| `apiType` | `openai-responses` | `openai-completions` — doesn’t work |
| `baseUrl` | `https://api.perplexity.ai/v1` | `/v1/agent` — invalid path |
| `model` | `perplexity/anthropic/claude-sonnet-4-6` | — |

> **Note: `baseUrl` must be `https://api.perplexity.ai/v1`, not `/v1/agent`.  
> The API type should be `openai-responses`.**

---

<div class="post-metadata">

**Author:** ![Kesku](https://sea1.discourse-cdn.com/flex001/user_avatar/community.perplexity.ai/kesku/32/898_2.png) [@Kesku](https://community.perplexity.ai/u/Kesku)\
**Post date:** [April 13, 2026, 3:57am UTC](https://community.perplexity.ai/t/does-anyone-try-to-use-perplexity-api-on-openclaw-couldnt-do-it/4760/5 "2026-04-13T03:57:30Z")

</div>

Good catch on the root cause! The upstream fix has since landed in [`pi-mono#2745`](https://github.com/badlogic/pi-mono/issues/2745) and pi 0.66.1 includes it. OpenClaw `2026.4.11` (the current `latest`) pulls in that version now.

A quick `npm update -g openclaw` should sort it out. Tool calling via Agent API works out of the box now, we verified chat + tool calls with `openai-responses` and `perplexity/anthropic/claude-sonnet-4-6` on `2026.4.11` without any patches.

[We’ve also updated our documentation with a guide on using our Agent API for Openclaw](https://docs.perplexity.ai/docs/getting-started/integrations/openclaw#agent-api-setup-use-perplexity-as-your-llm-provider)!

---

<div class="post-metadata">

**Author:** ![leonideo](https://sea1.discourse-cdn.com/flex001/user_avatar/community.perplexity.ai/leonideo/32/2238_2.png) [@leonideo](https://community.perplexity.ai/u/leonideo)\
**Post date:** [April 13, 2026, 4:15am UTC](https://community.perplexity.ai/t/does-anyone-try-to-use-perplexity-api-on-openclaw-couldnt-do-it/4760/6 "2026-04-13T04:15:53Z")

</div>

Got it thank u very much for fast update!
