Skip to content

mupromax/apivai-api-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

APIVAI API Examples

APIVAI is an OpenAI- and Anthropic-compatible API gateway for Claude and GPT models at a fraction of official list price. Because it's compatible, existing tools (Claude Code, Cursor, Cline, Codex CLI, the OpenAI/Anthropic SDKs) work by changing the base URL and key — no custom code. Pay-as-you-go, with crypto / USDT / Alipay, no VPN, no subscription.

Developer-focused examples for calling APIVAI with OpenAI-compatible request patterns. The repository keeps each example intentionally small so you can inspect the request shape, confirm credentials, and adapt the code to your own application.

Default API base URL used by these examples:

https://api.apivai.com/v1

What this repository is for

Use this repository when you want to:

  • Check that your APIVAI API key and network path are configured correctly.
  • See minimal Python, Node.js, and cURL requests before integrating a full SDK or application.
  • Verify model names with GET /v1/models instead of hardcoding a value.
  • Keep example code simple enough to copy into a local prototype and then replace with your own error handling, logging, and configuration.

This repository is not a production application framework. Treat it as a set of small connectivity and request-format examples.

Example entry points

Runtime File Purpose
Python examples/python-chat.py Sends a chat completion request from a small Python script.
Node.js examples/node-chat.js Sends a chat completion request with the built-in Node.js fetch API.
cURL examples/curl-chat.md Shows a shell-based request that is useful for quick endpoint testing.
Python streaming examples/python-streaming.py Reads streamed chat-completion chunks from APIVAI.
Node.js streaming examples/node-streaming.js Reads streamed chat-completion chunks with built-in Node.js APIs.
Models cURL examples/models-list-curl.md Lists available models before setting APIVAI_MODEL.

SDK & framework examples

Because the endpoint is OpenAI- and Anthropic-compatible, the official SDKs and popular frameworks work by overriding the base URL and key — no custom integration code.

SDK / framework File Notes
OpenAI SDK (Python) examples/openai-sdk-python.py Official openai package, base_url override.
OpenAI SDK (Node) examples/openai-sdk-node.js Official openai package, baseURL override.
Anthropic SDK (Python) examples/anthropic-sdk-python.py Official anthropic package against /v1/messages.
Anthropic SDK (Node) examples/anthropic-sdk-node.js Official @anthropic-ai/sdk package, baseURL override.
LangChain (Python) examples/langchain-python.py ChatOpenAI(base_url=...).
LlamaIndex (Python) examples/llamaindex-python.py OpenAILike(api_base=...).
Function calling (Python) examples/function-calling-python.py Tool-use round-trip via the OpenAI SDK.

Use with your editor or agent

These tools accept an OpenAI-compatible base URL + key — set https://api.apivai.com/v1 and a model from GET /v1/models:

Tool Guide
Claude Code docs/claude-code.md
Cursor docs/cursor.md
Codex CLI docs/codex-cli.md
Cline docs/cline.md
Aider docs/aider.md
Continue.dev docs/continue-dev.md

For Claude-specific workflows, confirm whether your tool expects OpenAI-compatible or Anthropic-compatible settings. See the APIVAI Claude API proxy page for current guidance: https://apivai.com/claude-api-proxy.

Requirements

Before running examples, make sure you have:

  • An APIVAI API key from your account.
  • Network access to https://api.apivai.com/v1.
  • One of the following local runtimes:
    • Python 3.9+ for examples/python-chat.py.
    • Node.js 18+ for examples/node-chat.js.
    • curl for examples/curl-chat.md.

Quick start

1) Set environment variables

All examples read these environment variables:

  • APIVAI_API_KEY: your secret API key.
  • APIVAI_BASE_URL: defaults to https://api.apivai.com/v1 when not set in supported examples.
  • APIVAI_MODEL: a model name returned for your account.

macOS/Linux:

export APIVAI_API_KEY="YOUR_APIVAI_API_KEY"
export APIVAI_BASE_URL="https://api.apivai.com/v1"
export APIVAI_MODEL="YOUR_MODEL_NAME"

PowerShell:

$env:APIVAI_API_KEY="YOUR_APIVAI_API_KEY"
$env:APIVAI_BASE_URL="https://api.apivai.com/v1"
$env:APIVAI_MODEL="YOUR_MODEL_NAME"

2) Discover available models

Model availability can vary by account and over time. Start by calling:

GET https://api.apivai.com/v1/models

Example:

curl -s "$APIVAI_BASE_URL/models" \
  -H "Authorization: Bearer $APIVAI_API_KEY" \
  -H "Content-Type: application/json"

Set APIVAI_MODEL to a model name returned by that response.

3) Run an example

python3 examples/python-chat.py
node examples/node-chat.js

For cURL, follow examples/curl-chat.md.

Common errors / troubleshooting

  • 401 Unauthorized: Confirm that APIVAI_API_KEY is set, has no extra spaces, and is sent as Authorization: Bearer <key>.
  • 404 Not Found: Check that APIVAI_BASE_URL includes /v1 and that the endpoint path is correct.
  • model_not_found or similar model errors: call GET /v1/models again and use a returned model name.
  • 429 Too Many Requests: Reduce request rate and retry with exponential backoff.
  • 5xx responses: retry after a short delay and capture any request identifiers or timestamps for support/debugging.
  • Empty or malformed responses: verify that the request body is valid JSON and that Content-Type: application/json is present.

For a longer setup walkthrough, see docs/setup.md. For testing commands, see docs/testing.md. For common questions, see docs/faq.md.

Additional developer guides:

Security notes

  • Never commit real API keys, tokens, or account identifiers.
  • Do not expose secret keys in browser or mobile client code; route requests through a server you control.
  • Prefer environment variables, a local .env file excluded from Git, or a managed secrets store.
  • Rotate keys immediately if they are pasted into logs, screenshots, issues, pull requests, or chat messages.
  • Review logs before sharing them publicly; request and response bodies may contain sensitive user data.

Repository structure

.
├── README.md
├── .env.example
├── examples/
│   ├── python-chat.py
│   ├── node-chat.js
│   ├── curl-chat.md
│   ├── python-streaming.py
│   ├── node-streaming.js
│   ├── models-list-curl.md
│   ├── openai-sdk-python.py
│   ├── openai-sdk-node.js
│   ├── anthropic-sdk-python.py
│   ├── langchain-python.py
│   ├── llamaindex-python.py
│   └── function-calling-python.py
├── docs/
│   ├── setup.md
│   ├── faq.md
│   ├── testing.md
│   ├── openai-compatible-endpoint.md
│   ├── claude-code.md
│   ├── cursor.md
│   ├── codex-cli.md
│   ├── cline.md
│   ├── aider.md
│   └── troubleshooting.md
└── .github/
    └── ISSUE_TEMPLATE/

License

See LICENSE.

Contributors