Production-ready examples for the APIMart OpenAI-compatible AI API gateway — chat, images, videos, audio, and account utilities through one unified API.
APIMart provides a unified gateway for 500+ AI models — chat models such as GPT, Claude and Gemini; image models such as GPT-Image-2, Imagen and Nano Banana; video models such as Sora, Veo and Kling; plus audio models — with a familiar OpenAI-style API surface.
- Base URL:
https://api.apimart.ai/v1 - Docs: https://docs.apimart.ai
- LLM-readable docs index: https://docs.apimart.ai/llms.txt
- Get an API key: https://apimart.ai/keys
- Model market: https://apimart.ai/market
export APIMART_API_KEY="sk-your-key"
export APIMART_BASE_URL="https://api.apimart.ai/v1"curl --request POST \
--url "$APIMART_BASE_URL/chat/completions" \
--header "Authorization: Bearer $APIMART_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "Explain APIMart in one sentence."}
]
}'python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python examples/python/chat_completions.pynode examples/javascript/chat-completions.mjs| Area | Endpoint | Example files | Docs |
|---|---|---|---|
| Chat completions | POST /v1/chat/completions |
examples/curl/chat-completions.sh, examples/python/chat_completions.py, examples/javascript/chat-completions.mjs |
General Chat API |
| Image generation | POST /v1/images/generations |
examples/curl/gpt-image-2.sh, examples/python/gpt_image_2.py, examples/javascript/gpt-image-2.mjs |
GPT-Image-2 API |
| Video generation | POST /v1/videos/generations |
examples/curl/sora-2-video.sh, examples/python/sora_2_video.py, examples/javascript/sora-2-video.mjs |
Sora 2 API |
| Async task polling | GET /v1/tasks/{task_id} |
examples/curl/task-status.sh, examples/python/poll_task.py, examples/javascript/task-status.mjs |
Task Status |
| API key balance | GET /v1/balance |
examples/curl/balance.sh, examples/python/balance.py |
Token Balance |
| Postman | Collection v2.1 | postman/APIMart.postman_collection.json |
Import into Postman |
Most text models can be called with the OpenAI SDK by changing the base URL and API key:
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["APIMART_API_KEY"],
base_url="https://api.apimart.ai/v1",
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Write a haiku about APIs."}],
)
print(response.choices[0].message.content)For async media models, submit a generation task first and then poll GET /v1/tasks/{task_id}?language=en until it completes.
| Variable | Default | Description |
|---|---|---|
APIMART_API_KEY |
required | Bearer token from https://apimart.ai/keys. |
APIMART_BASE_URL |
https://api.apimart.ai/v1 |
API base URL. |
APIMART_MODEL |
gpt-4o |
Chat model used by chat examples. |
APIMART_TASK_ID |
none | Task ID used by polling examples. |
- Website: https://apimart.ai
- API documentation: https://docs.apimart.ai
- Documentation index for AI agents: https://docs.apimart.ai/llms.txt
- API keys: https://apimart.ai/keys
- Pricing: https://apimart.ai/pricing
- GitHub organization: https://github.com/ApiMartAI
- Prompt gallery: https://github.com/ApiMartAI/best-gpt-image-2-prompts
- Do not commit real API keys. Use
.envlocally and.env.exampleas a template. - Generated image and video URLs may expire; download assets you need to keep.
- Media generation endpoints are asynchronous. Store the returned
task_idand poll the task endpoint.
MIT — see LICENSE.