Call Bearly's zero-retention API
Call Claude, GPT, and Grok from your own code with the official OpenAI or Anthropic SDK and a Bearly API key. Every API request goes to a zero-retention route: the model provider doesn’t keep your prompt or the model’s response after processing them. This page gets you to a first answer; Use the Bearly API is the full reference.
Before you start
Section titled “Before you start”-
Create an API key. In Bearly, open your account menu and select Developers. Under API Keys, select Create API Key (or New Key if you already have one), add a note such as “My script”, select Create, and copy the key. If Developers or API Keys is missing, your team administrator has turned off API access.
-
Store it in an environment variable. The examples read
BEARLY_API_KEY:Terminal window export BEARLY_API_KEY="paste-your-key-here" -
Install the SDK you’ll use:
pip install openai anthropicornpm install openai @anthropic-ai/sdk.
You don’t need an OpenAI or Anthropic key. Requests spend your Bearly plan’s allowance and credits, the same as chat.
Base URLs
Section titled “Base URLs”| SDK | Base URL | Models |
|---|---|---|
| OpenAI (Responses and Chat Completions) | https://api.bearly.ai/v1 |
GPT, Grok, Bearly’s own models, and the others that list these APIs |
| Anthropic (Messages) | https://api.bearly.ai |
Claude |
If your code already reads OPENAI_BASE_URL and OPENAI_API_KEY, or ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY, you can set those to the base URL and your Bearly key instead of changing code.
Find a model
Section titled “Find a model”Listing models doesn’t need a key:
curl https://api.bearly.ai/v1/modelsEach model lists the APIs it works with under endpoints: /v1/responses, /v1/chat/completions, or /v1/messages. Use a model only with an API it lists, and copy its id exactly. To get the list in Anthropic’s format, which includes only Claude models, add the version header:
curl https://api.bearly.ai/v1/models -H "anthropic-version: 2023-06-01"From code, client.models.list() returns the same lists in either SDK. Models can be added or removed, so check the list rather than hard-coding one forever.
Call GPT with the OpenAI SDK
Section titled “Call GPT with the OpenAI SDK”import os
from openai import OpenAI
client = OpenAI( base_url="https://api.bearly.ai/v1", api_key=os.environ["BEARLY_API_KEY"],)
response = client.responses.create( model="gpt-6.1-sol", input="In one sentence, what is zero data retention?", max_output_tokens=1000,)print(response.output_text)import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.bearly.ai/v1", apiKey: process.env.BEARLY_API_KEY,});
const response = await client.responses.create({ model: "gpt-6.1-sol", input: "In one sentence, what is zero data retention?", max_output_tokens: 1000,});console.log(response.output_text);max_output_tokens caps the reply, including the model’s reasoning, so a test can’t run up a large bill. The same client works with chat.completions.create for models that list /v1/chat/completions.
Call Claude with the Anthropic SDK
Section titled “Call Claude with the Anthropic SDK”import os
from anthropic import Anthropic
client = Anthropic( base_url="https://api.bearly.ai", api_key=os.environ["BEARLY_API_KEY"],)
message = client.messages.create( model="claude-haiku-5-5", max_tokens=200, messages=[{"role": "user", "content": "In one sentence, what is zero data retention?"}],)print(next(block.text for block in message.content if block.type == "text"))import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ baseURL: "https://api.bearly.ai", apiKey: process.env.BEARLY_API_KEY,});
const message = await client.messages.create({ model: "claude-haiku-5-5", max_tokens: 200, messages: [{ role: "user", content: "In one sentence, what is zero data retention?" }],});console.log(message.content.find((block) => block.type === "text")?.text);Claude models work only through the Anthropic SDK, and GPT and Grok only through the OpenAI SDK. If your code stops reading a stream early, the model still finishes the response and the full response is billed.
Errors
Section titled “Errors”Errors come back in the SDK’s own format, so the SDK raises its usual exception, such as AuthenticationError. A wrong key looks like this:
{"error": {"message": "invalid or expired API key", "type": "invalid_request_error", "param": null, "code": null}}{"type": "error", "error": {"type": "authentication_error", "message": "invalid or expired API key"}}| Status | Meaning | What to do |
|---|---|---|
401 |
The key is missing, wrong, or deleted. | Check BEARLY_API_KEY, or create a new key under API Keys. |
402 |
The model needs a different plan, or your allowance or credits can’t cover the request. | Add credits, change plans, or pick another model. |
403 |
Your team’s policy turns off API access or doesn’t allow this model. | Ask your team administrator, or pick an allowed model. |
404 model_not_found |
The model ID is wrong, the model doesn’t support the API you called, or it’s no longer offered. | Check the model list and switch SDK if needed. |
429 |
Your account already has 10 API requests running. | Wait for one to finish. Both SDKs retry twice by default; keep retries and parallel jobs bounded. |
The full reference covers the rest.
What isn’t supported
Section titled “What isn’t supported”- Stored responses. Responses requests always run with storage off, so
previous_response_id, background mode, and retrieving a past response aren’t available. Send the conversation history with each request. - Provider-hosted tools. Built-in web search, file search, code execution, and provider-hosted MCP servers return a
400error. - Gemini. Gemini models aren’t available through the API.
- Other endpoints. Embeddings, images, audio, fine-tuning, and token counting aren’t available.
Related
Section titled “Related”- Use the Bearly API: the full reference, with per-model tool-calling limits, team controls, and every error.
- Use zero-data-retention models: what the zero-data-retention label means.