Skip to content

Call Bearly's zero-retention API

View as markdown

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.

  1. 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.

  2. Store it in an environment variable. The examples read BEARLY_API_KEY:

    Terminal window
    export BEARLY_API_KEY="paste-your-key-here"
  3. Install the SDK you’ll use: pip install openai anthropic or npm 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.

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.

Listing models doesn’t need a key:

Terminal window
curl https://api.bearly.ai/v1/models

Each 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:

Terminal window
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.

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)

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.

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"))

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 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}}
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.

  • 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 400 error.
  • Gemini. Gemini models aren’t available through the API.
  • Other endpoints. Embeddings, images, audio, fine-tuning, and token counting aren’t available.