Meta Llama API
Connect AISIX AI Gateway to the Meta Llama API so applications can use one caller-facing API while AISIX stores the upstream Llama credential, controls model access, and records usage.
The Llama API provides an OpenAI-compatible endpoint. AISIX discovers it through the community provider catalog and uses the openai adapter with bearer authentication.
| Setting | Value used by AISIX |
|---|---|
| Catalog provider ID | llama |
| API base | https://api.llama.com/compat/v1/ |
| Example upstream model | Llama-3.3-70B-Instruct |
| Authentication | Bearer API key |
Prerequisites
Before configuring the provider, prepare:
- Access to AISIX Cloud with an environment, an attached gateway, and a write-scoped admin token. For On-Premises, follow the AISIX Cloud Quickstart. To request Hybrid Cloud access, contact API7.
- A Meta Llama API key and access to the model you plan to use.
curlandjq.
Export the AISIX connection details:
export AISIX_CP="http://localhost:8080/api"
export AISIX_TOKEN="aisix_pat_YOUR_ADMIN_TOKEN"
export ENV_ID="YOUR_ENVIRONMENT_ID"
export AISIX_PROXY="http://127.0.0.1:3000"
Configure the Meta Llama API Upstream
Create a provider key, a model alias, and a caller API key.
Create a Provider Key
Export the upstream credential:
export LLAMA_API_KEY="YOUR_LLAMA_API_KEY"
Create the provider key:
PROVIDER_KEY_ID=$(
curl -sS -X POST "$AISIX_CP/provider_keys" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"display_name": "llama-api-prod",
"provider": "llama",
"api_key": "'"${LLAMA_API_KEY}"'",
"api_base": "https://api.llama.com/compat/v1/",
"allowed_environments": ["'"${ENV_ID}"'"]
}' | jq -er '.provider_key.id'
)
echo "$PROVIDER_KEY_ID"
provider must be the catalog ID llama. Do not add adapter: AISIX derives the openai adapter for catalog providers and accepts an explicit adapter only for BYO provider keys.
The API base includes /compat/v1/. AISIX normalizes the trailing slash and appends /chat/completions, producing the upstream route https://api.llama.com/compat/v1/chat/completions.
Create a Model
Create a caller-facing alias for the upstream model:
MODEL_ID=$(
curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/models" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"display_name": "llama-api-prod",
"model_name": "Llama-3.3-70B-Instruct",
"provider_key_id": "'"${PROVIDER_KEY_ID}"'"
}' | jq -er '.model.id'
)
echo "$MODEL_ID"
display_name is the stable alias applications send to AISIX. model_name is the exact ID sent to Meta. Check the Meta Llama model documentation before substituting another model because availability can depend on the account and API release.
Create a Caller API Key
Create a caller key limited to this model:
AISIX_API_KEY=$(
curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/api_keys" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"display_name": "llama-api-caller",
"allowed_models": ["'"${MODEL_ID}"'"]
}' | jq -er '.plaintext'
)
echo "$AISIX_API_KEY"
The plaintext caller key is returned only when the resource is created. Store it securely.
Verify the Provider Connection
Send a chat request through AISIX:
curl -sS -X POST "$AISIX_PROXY/v1/chat/completions" \
-H "Authorization: Bearer $AISIX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "llama-api-prod",
"messages": [
{
"role": "user",
"content": "Say hello from the Meta Llama API."
}
]
}'
AISIX resolves llama-api-prod to Llama-3.3-70B-Instruct, sends a bearer-authenticated request to the Llama API, and returns an OpenAI-compatible response.
Endpoint Coverage
The normalized /v1/chat/completions route is the primary path for this provider. AISIX can also bridge compatible /v1/responses and /v1/messages requests through the same chat adapter. Embeddings require a model and endpoint that Meta exposes on this API base.
Image generation, video generation, and rerank use route-specific provider allowlists and do not accept the llama provider value. See Provider Compatibility.
Troubleshooting
| Symptom | Check |
|---|---|
Upstream 401 or 403 | Confirm LLAMA_API_KEY is active and the account can use the selected model. |
Upstream 404 | Confirm the API base includes /compat/v1 and copy the current model ID from Meta. |
Provider key creation returns 400 | Use provider: "llama" without an adapter field. |
| AISIX returns model access denied | Confirm the caller key's allowed_models contains the model resource ID. |
For credential rotation and provider-level overrides, see Provider Credentials.