OPENAI SDK
OpenAI SDK base_url
Create an API key, point the official OpenAI SDK at Half API, and keep the same chat completions call. Use model names from the console.
Quickstart
- 1. Create an accountSign up with email at app.halfapi.com.
- 2. Pay with USDTMinimum top-up is $1. Credits are added when the payment completes.
- 3. Create an API keyCopy the
sk-secret. Use a GPT key for the OpenAI SDK. - 4. Set
base_urlKeep the OpenAI SDK. Change only the host and the key.
Configure the SDK
| Field | Value |
|---|---|
| Base URL | https://api.halfapi.com/v1 |
| API key | Console key starting with sk- |
| Model | A name from the console list |
Python:
from openai import OpenAI
client = OpenAI(
api_key="sk-...",
base_url="https://api.halfapi.com/v1",
)
resp = client.chat.completions.create(
model="YOUR_MODEL",
messages=[{"role": "user", "content": "ping"}],
)
print(resp.choices[0].message.content)
Node:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.HALFAPI_KEY,
baseURL: "https://api.halfapi.com/v1",
});
Replace
YOUR_MODEL with a name from the console list.Try it
Run the snippet with a real key and a console model name. A 401 means the key is missing or wrong. A 402 or insufficient credit means the USDT payment has not completed, or the balance is empty.
Troubleshooting
- base_url
- Set base_url or baseURL to https://api.halfapi.com/v1.
- Wrong key
- The OpenAI SDK needs a GPT key. A Claude key will not work here.
- USDT
- Payments are final once the gateway marks them complete.
- Anthropic vs OpenAI host
- Claude Code uses
https://api.halfapi.comwith no/v1. The OpenAI SDK uses/v1.