A practical multi-language collection of examples for connecting to OpenAI-compatible APIs.
This repository provides minimal, runnable examples for developers who want to use OpenAI-compatible APIs across different programming languages.
What you'll learn:
- How to configure API base URL and key
- How to send a simple chat completion request
- How to reuse the same pattern across languages
| Language | Example File | Documentation |
|---|---|---|
| Python | python/chat_completion.py | python/README.md |
| Node.js | node/chat_completion.js | node/README.md |
| Go | go/main.go | go/README.md |
| curl | curl/chat_completion.sh | curl/README.md |
cp .env.example .envEdit .env with your credentials:
API_KEY=your_api_key_here
BASE_URL=https://tken.shop/v1
MODEL=gpt-4o-miniChoose your language:
# Python
cd python && pip install -r requirements.txt && python chat_completion.py
# Node.js
cd node && npm install && node chat_completion.js
# Go
cd go && go run main.go
# curl
chmod +x curl/chat_completion.sh && ./curl/chat_completion.sh| Variable | Description | Example |
|---|---|---|
API_KEY |
Your API key | sk-xxxxx |
BASE_URL |
API endpoint (must end with /v1) |
https://tken.shop/v1 |
MODEL |
Model identifier | gpt-4o-mini |
All examples send a POST request to {BASE_URL}/chat/completions:
{
"model": "gpt-4o-mini",
"messages": [
{"role": "user", "content": "Hello!"}
]
}| Example | Description |
|---|---|
| Chat Completion | Simple chat request with text response |
| Streaming | (Not included in basic examples) |
| Embeddings | (Not included in basic examples) |
These examples work with any OpenAI-compatible API.
For testing, one possible provider is https://tken.shop - an OpenAI-compatible gateway with free access options.
If you move beyond simple examples and need account rotation, 429 retry, proxy support, or model-aware routing, see:
That repository is the more production-oriented gateway layer in this repo family.
- Setup Guide - Environment configuration
- Compatibility Guide - API compatibility explained
openai-compatible-api-examples/
├── README.md
├── .env.example
├── python/
│ ├── README.md
│ ├── requirements.txt
│ └── chat_completion.py
├── node/
│ ├── README.md
│ ├── package.json
│ └── chat_completion.js
├── go/
│ ├── README.md
│ ├── go.mod
│ └── main.go
├── curl/
│ ├── README.md
│ └── chat_completion.sh
└── docs/
├── compatibility.md
└── setup.md
MIT License - see LICENSE