Skip to content

Curl Examples

This guide provides curl examples for interacting with Adastra LLMGW directly via HTTP requests.

Prerequisites

Set your environment variables:

export LLMGW_API_ENDPOINT="https://<llmgw-deployment-url>"
export LLMGW_API_KEY="<YOUR_LLMGW_API_KEY>"

Supported authentication headers

LLMGW accepts any of the following headers for passing your API key:

  • Authorization: Bearer ${LLMGW_API_KEY} — standard OAuth bearer token format
  • api-key: ${LLMGW_API_KEY} — used by the Azure OpenAI SDK (with api_key=)
  • x-api-key: ${LLMGW_API_KEY} — used by the Anthropic SDK

Multiple authentication headers are allowed per request if their API key values match.

Azure OpenAI Endpoint

Basic Chat Completion

curl -X POST "$LLMGW_API_ENDPOINT/azure-open-ai/deployments/gpt-4.1/chat/completions?api-version=2025-01-01-preview" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LLMGW_API_KEY" \
  -H "llmgw-user: your-user" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": "What is the weather like?"
      }
    ]
  }'

Streaming Chat Completion

curl -X POST "$LLMGW_API_ENDPOINT/azure-open-ai/deployments/gpt-4.1/chat/completions?api-version=2025-01-01-preview" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LLMGW_API_KEY" \
  -H "llmgw-user: your-user" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": "Tell me a story"
      }
    ],
    "stream": true
  }'

View Response Headers

Add the -i flag to see response headers including LLMGW metadata:

curl -i -X POST "$LLMGW_API_ENDPOINT/azure-open-ai/deployments/gpt-4.1/chat/completions?api-version=2025-01-01-preview" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LLMGW_API_KEY" \
  -H "llmgw-user: your-user" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": "What is the weather like?"
      }
    ]
  }'

Response headers will include:

x-llmgw-cost: 0.00004
x-llmgw-request-id: 3cb26481-d869-4923-8093-3feb92f8d9fc
x-llmgw-model-id: azure-us-gpt35
x-llmgw-attempts: 1

For full details and what headers are included, see Response Headers.

OpenAI Endpoint

Basic Chat Completion

curl -X POST "$LLMGW_API_ENDPOINT/openai/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LLMGW_API_KEY" \
  -H "llmgw-user: your-user" \
  -d '{
    "model": "gpt-4.1",
    "messages": [
      {
        "role": "user",
        "content": "What is the weather like?"
      }
    ]
  }'

Create Embeddings

curl -X POST "$LLMGW_API_ENDPOINT/openai/v1/embeddings" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LLMGW_API_KEY" \
  -H "llmgw-user: your-user" \
  -d '{
    "model": "text-embedding-3-large",
    "input": "Text to embed"
  }'

List Available Models

curl -X GET "$LLMGW_API_ENDPOINT/openai/models"

Call AWS Bedrock Models via OpenAI Endpoint

curl -X POST "$LLMGW_API_ENDPOINT/openai/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LLMGW_API_KEY" \
  -H "llmgw-user: your-user" \
  -d '{
    "model": "anthropic.claude-sonnet-4-5-20250929-v1:0",
    "messages": [
      {
        "role": "user",
        "content": "Tell me a story"
      }
    ]
  }'

Anthropic Endpoint

Create a Message

curl -X POST "$LLMGW_API_ENDPOINT/anthropic/v1/messages" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $LLMGW_API_KEY" \
  -H "llmgw-user: your-user" \
  -d '{
    "model": "anthropic.claude-sonnet-4-5-20250929-v1:0",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "What is the weather like?"
      }
    ]
  }'

Streaming Message

curl -X POST "$LLMGW_API_ENDPOINT/anthropic/v1/messages" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $LLMGW_API_KEY" \
  -H "llmgw-user: your-user" \
  -d '{
    "model": "anthropic.claude-sonnet-4-5-20250929-v1:0",
    "max_tokens": 1024,
    "stream": true,
    "messages": [
      {
        "role": "user",
        "content": "Tell me a story"
      }
    ]
  }'

AWS Bedrock Endpoint

Invoke Claude Model

curl -X POST "$LLMGW_API_ENDPOINT/aws-bedrock/model/anthropic.claude-sonnet-4-5-20250929-v1:0/invoke" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LLMGW_API_KEY" \
  -H "llmgw-user: your-user" \
  -d '{
    "max_tokens": 150,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "What is the weather like?"
          }
        ]
      }
    ]
  }'

Common Headers

All LLMGW endpoints support these custom headers:

Header Description Required
llmgw-user User identifier for tracking and billing Check with admin

Response Headers

All responses include LLMGW metadata headers:

  • x-llmgw-request-id - Unique request identifier for debugging
  • x-llmgw-model-id - Actual model used (may differ due to load balancing)
  • x-llmgw-cost - Request cost in USD
  • x-llmgw-attempts - Number of retry attempts
  • x-llmgw-remaining-limits - Remaining usage limits

See Response Headers for more details.

Tips

  • Use -i flag to view response headers
  • Use -v flag for verbose output including request headers
  • Use -s flag for silent mode (no progress meter)
  • Set environment variables to avoid repeating credentials
  • Add | jq to prettify JSON responses (requires jq to be installed)

Example with JSON formatting:

curl -s -X POST "$LLMGW_API_ENDPOINT/openai/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LLMGW_API_KEY" \
  -d '{
    "model": "gpt-4.1",
    "messages": [{"role": "user", "content": "What is the weather like?"}]
  }' | jq