15% off all models 🎉 Every model at 85% of OpenRouter list price.Browse models →

Quickstart

Make your first ApiFlux request with an OpenAI-compatible, Anthropic, or Gemini API.

Use this guide to send a small text request through ApiFlux and confirm that the gateway recorded it.

What you will build

You will choose an interface model ID, call it through one of the supported API protocols, and then find the request in your ApiFlux logs.

Success criterion

Your request returns ApiFlux is ready. and appears in the usage logs for the same API key.

Before you start

  1. Create an ApiFlux API key. Use a non-production key while evaluating the gateway.
  2. Choose a model and copy an Interface model ID that supports the protocol you plan to use.
  3. Open a terminal with cURL, Python 3, or Node.js 18+ available.

Set these environment variables before running an example:

terminal
export APIFLUX_BASE_URL="https://apiflux.ai"
export APIFLUX_API_KEY="YOUR_APIFLUX_API_KEY"
export APIFLUX_MODEL="YOUR_INTERFACE_MODEL_ID"

Run Python examples with python3 quickstart.py and TypeScript examples with npx tsx quickstart.ts.

Keep the key private

Never commit an ApiFlux API key to source control or expose it in browser-side application code.

Send your first request

Choose the protocol that matches your existing SDK or request format. OpenAI-compatible is the recommended starting point when you do not have a protocol requirement.

Send a Chat Completions request to POST /v1/chat/completions with Bearer authentication.

terminal
curl "${APIFLUX_BASE_URL}/v1/chat/completions" \
  --header "Authorization: Bearer ${APIFLUX_API_KEY}" \
  --header "Content-Type: application/json" \
  --data @- <<JSON
{
  "model": "${APIFLUX_MODEL}",
  "messages": [
    {
      "role": "user",
      "content": "Reply with exactly: ApiFlux is ready."
    }
  ]
}
JSON

A successful response includes the assistant message in choices[0].message.content:

response.json
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "ApiFlux is ready."
      }
    }
  ]
}

Send a Messages request to POST /v1/messages with the Anthropic authentication headers.

terminal
curl "${APIFLUX_BASE_URL}/v1/messages" \
  --header "x-api-key: ${APIFLUX_API_KEY}" \
  --header "anthropic-version: 2023-06-01" \
  --header "Content-Type: application/json" \
  --data @- <<JSON
{
  "model": "${APIFLUX_MODEL}",
  "max_tokens": 64,
  "messages": [
    {
      "role": "user",
      "content": "Reply with exactly: ApiFlux is ready."
    }
  ]
}
JSON

A successful response includes the assistant message in content[0].text:

response.json
{
  "content": [
    {
      "type": "text",
      "text": "ApiFlux is ready."
    }
  ],
  "stop_reason": "end_turn"
}

Send a Generate Content request to POST /v1beta/models/{model}:generateContent with the Gemini authentication header.

terminal
curl "${APIFLUX_BASE_URL}/v1beta/models/${APIFLUX_MODEL}:generateContent" \
  --header "x-goog-api-key: ${APIFLUX_API_KEY}" \
  --header "Content-Type: application/json" \
  --data @- <<JSON
{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Reply with exactly: ApiFlux is ready." }
      ]
    }
  ]
}
JSON

A successful response includes the assistant message in candidates[0].content.parts[0].text:

response.json
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          { "text": "ApiFlux is ready." }
        ]
      }
    }
  ]
}

Verify the request

Open Logs in the ApiFlux console and find the request you just sent. Confirm the model, timestamp, token usage, and request status match the response from your terminal.

Keep the X-Request-Id response header when a request fails. It identifies the same request in ApiFlux logs and is the value support needs to investigate the failure.

The response succeeded but no log appears

Confirm that the API key belongs to the same account you are using in the console, then refresh the logs after a few seconds.

Troubleshooting

ResultWhat to check
401 UnauthorizedThe API key and the protocol-specific authentication header.
400 Bad RequestThe interface model ID, request body, and protocol compatibility shown in the model catalog.
404 Not FoundThe base URL and protocol endpoint path.
429 Too Many RequestsAccount credits, model limits, and configured rate limits.

Next steps