API reference
Reference for the USA Inference Labs model listing and chat completions endpoints, including Bearer authentication, curl examples, and a live API playground.
The base URL is https://api.usainferencelabs.com/v1. Both endpoints require a USA Inference Labs API key.
Try the API
Use your USA Inference Labs API key to send a live request and inspect the JSON response.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.usainferencelabs.com/v1",
api_key=os.environ["USA_INFERENCE_LABS_API_KEY"],
)
completion = client.chat.completions.create(
model="primary-v1",
messages=[{"role": "user", "content": "Say hello in one sentence."}],
max_tokens=64,
)
print(completion.choices[0].message.content)Authentication
Send your key in the Authorization header with the Bearer scheme. For scripts and applications, read the key from an environment variable or secret manager.
Authorization: Bearer <USA_INFERENCE_LABS_API_KEY>List models
GET /v1/modelsReturns an object with a data array. Each entry has an id you can use as the model in a completion request.
curl --fail-with-body --silent --show-error \
https://api.usainferencelabs.com/v1/models \
-H "Authorization: Bearer ${USA_INFERENCE_LABS_API_KEY}"Create a chat completion
POST /v1/chat/completions
Content-Type: application/jsonSend a model alias and one or more messages. This example requests a non-streaming response.
| Field used in this example | Type | Description |
|---|---|---|
model | string | An alias returned by the model list, such as coder-v1 |
messages | array | Conversation messages. This example sets role to user and uses a text content value |
max_tokens | integer | Upper bound on generated tokens. Use a small value when testing |
stream | boolean | Set to false to receive a JSON completion |
curl --fail-with-body --silent --show-error \
https://api.usainferencelabs.com/v1/chat/completions \
-H "Authorization: Bearer ${USA_INFERENCE_LABS_API_KEY}" \
-H "Content-Type: application/json" \
--data '{
"model": "coder-v1",
"messages": [
{"role": "user", "content": "Say hello in one sentence."}
],
"max_tokens": 32,
"stream": false
}'Read the generated text from choices[0].message.content. A response includes fields like these.
{
"model": "coder-v1",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "Hello. How can I help?" },
"finish_reason": "stop"
}
]
}Handle errors
| HTTP status | What to check |
|---|---|
400 | Check that the JSON is valid and includes the fields for the operation |
401 | Check that the Authorization header contains a valid Bearer key |
429 | Reduce request volume and back off before retrying |
5xx | Retry a temporary failure with bounded backoff. Keep the request ID for support if one was returned |
See the Python quickstart for an SDK example and the security and data handling overview for credential and request-handling guidance.