---
title: "Connecting OpenClaw to the Claude API"
description: "A tutorial on configuring OpenClaw to use the 1折AI Claude API relay, covering the endpoint address, API key, and model selection, along with protocol choices, configuration examples, verification steps, and common errors."
headingIds: {"Verifying the Connection and Troubleshooting":"section-1","Costs and Other Integration Methods":"section-2"}
---

<aside className="docs-publication" data-pagefind-ignore>

Documentation maintained by [1ZheAI](https://1zheai.com/en/editorial/#publisher). [Sources and corrections](https://1zheai.com/en/editorial/).

Found an error? [Contact support](mailto:support@1zheai.com) with the page address and a description. Do not send API keys or account credentials.

</aside>
Use OpenClaw's custom provider feature to connect to 1折AI. First, [create an API key](/en/docs/api-keys/) and confirm the [currently available models](/en/docs/models/). The model IDs below are examples; adjust them according to your key's permissions.

<Note>
Official configuration verification date: 2026-10-15. The following configuration is compiled based on official documentation; end-to-end verification on this site has not yet been completed. Please first complete a short Q&A and tool-call verification before using it for long tasks. OpenAI / GPT models are now live; see the [model description](/en/docs/models/) for the model list and pricing.
</Note>

Based on [custom provider](https://docs.openclaw.ai/gateway/config-tools/custom-providers) and [configuration example](https://docs.openclaw.ai/gateway/configuration-examples), merge in `~/.openclaw/openclaw.json`:

```json
{
  "agents": {
    "defaults": {
      "model": { "primary": "onezhe/claude-sonnet-4-6" },
      "models": { "onezhe/claude-sonnet-4-6": { "alias": "1折AI Claude" } }
    }
  },
  "models": {
    "mode": "merge",
    "providers": {
      "onezhe": {
        "baseUrl": "https://1zheai.com",
        "apiKey": "${ONEZHE_API_KEY}",
        "api": "anthropic-messages",
        "models": [
          { "id": "claude-sonnet-4-6", "name": "Claude Sonnet 4.6" }
        ]
      }
    }
  }
}
```

Make sure the process actually running the Gateway can read `ONEZHE_API_KEY`; environment variables in your terminal are not necessarily passed to an existing background service. The [official Synthetic documentation](https://docs.openclaw.ai/providers/synthetic) explicitly states that the Anthropic client automatically appends `/v1`, so do not include `/v1` here, nor fill in the full `/v1/messages`.

When switching to Chat Completions, replace them as a pair with `baseUrl: "https://1zheai.com/v1"` and `api: "openai-completions"`. Despite the name containing "completions", this adapter corresponds to `/v1/chat/completions`; do not mistakenly select `openai-responses`. If you already have a model allowlist, keep the other entries and add the new model. The examples do not fabricate cost or context parameters; if your currently installed version's validation requires additional metadata, verify the actual model capabilities before adding them.

## Verifying the Connection and Troubleshooting

1. Save and reload the configuration, and confirm that the currently selected provider is `onezhe` or the custom model you added.
2. Send a short question to confirm a response is returned; then try a small, reversible task to separately verify tool calls and multi-turn conversation.
3. Open the [call log](/en/docs/usage-logs/) and check the request time, model, status, and usage. A single successful text response does not mean all Agent capabilities are compatible.
4. If you encounter a 404, check whether the address and protocol in this article match; if you encounter a 401, check the key's origin and whether the process read the environment variables; if you encounter a 429, review the rate-limiting information before retrying. For more cases, see [error codes and troubleshooting](/en/docs/troubleshooting/).

Store keys only in your local environment or the tool's credential store; do not commit them to code repositories, screenshots, or public logs. Background services may not inherit terminal environment variables; auxiliary models, search, and other tools may also have independent provider settings that need to be checked separately.

## Costs and Other Integration Methods

Check [Claude API real-time pricing](https://1zheai.com/en/pricing/) and [billing rules](/en/docs/pricing-explained/). If you need other clients, return to the [tool integration directory](/en/docs/integrations/); if you are writing your own program, use the [SDK and developer guide](/en/docs/guides/).
