01 / Recommended: Oh My Pi
Oh My Pi installs the omp command. This setup uses openai-responses and discovers your available model IDs directly from SafeAPI. Your API key belongs in the environment variable—not in the YAML file.
curl -fsSL https://omp.sh/install | sh
mkdir -p ~/.omp/agent
cat > ~/.omp/agent/models.yml <<'YAML'
providers:
safeapi:
baseUrl: https://safeapi.cc/v1
apiKey: SAFEAPI_API_KEY
api: openai-responses
discovery:
type: openai-models-list
YAML
export SAFEAPI_API_KEY='sk-safe_...'
omp models refresh safeapi
omp -p --model safeapi/gpt-6.2-astra "Reply with only OK"For Chat Completions instead, change api: openai-responses to api: openai-completions. For Anthropic Messages, use api: anthropic-messages with auth: apiKey.
02 / OpenAI-compatible request
The base URL is https://safeapi.cc/v1. Authenticate with Authorization: Bearer sk-safe_....
curl https://safeapi.cc/v1/chat/completions \
-H "Authorization: Bearer $SAFEAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-6.2-astra","messages":[{"role":"user","content":"Hello"}]}'import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://safeapi.cc/v1",
apiKey: process.env.SAFEAPI_API_KEY,
});
const response = await client.chat.completions.create({
model: "gpt-6.2-astra",
messages: [{ role: "user", content: "Hello" }],
});03 / Streaming
Set stream: true. SafeAPI forwards SSE events as they arrive and cancels the upstream request if your client disconnects. For Chat Completions, SafeAPI requests the final usage chunk automatically so billing does not depend on your SDK configuration.
curl -N https://safeapi.cc/v1/chat/completions \
-H "Authorization: Bearer $SAFEAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-6.2-astra","stream":true,"messages":[{"role":"user","content":"Hello"}]}'04 / Claude Code and Anthropic SDKs
Anthropic clients use the base URL without /v1; the client appends the route itself.
export ANTHROPIC_BASE_URL=https://safeapi.cc export ANTHROPIC_AUTH_TOKEN=sk-safe_... claude
05 / Other coding agents
| Client | Provider / protocol | Base URL |
|---|---|---|
| Cline / Roo Code | OpenAI Compatible | https://safeapi.cc/v1 |
| Codex CLI | Responses | https://safeapi.cc/v1 |
| Continue | OpenAI | https://safeapi.cc/v1 |
| Claude Code | Anthropic Messages | https://safeapi.cc |
06 / Errors and retries
401 means a missing, invalid, or revoked key. 402 means insufficient available balance. 429 means a user or capacity limit; honor Retry-After. Retry upstream 5xx errors with exponential backoff, but never automatically repeat a stream after output has started.
07 / Privacy
SafeAPI logs request metadata needed for billing and reliability: account, model, token counts, timings, status, and cost. It does not log prompts, completions, authorization headers, or API keys.