Gate.AI›Blog›Gate.AI Quick Start: Access the API with Python, Node.js, and curl

    Gate.AI Quick Start: Access the API with Python, Node.js, and curl

    Guides

    Gate.AI provides an OpenAI-compatible API interface. Developers can send chat completion requests via Python, Node.js, curl, and other compatible AI development tools. If you’ve already used an OpenAI-style SDK or REST requests, connecting to the Gate.AI API usually just requires swapping your API key and Base URL. You don’t need to change the request structure. This quick start guide includes a required configuration step, one connection-path selection, and three mutually exclusive implementations in Python, Node.js, and curl. Advanced topics such as streaming architecture, account permissions, production monitoring, and billing controls are out of scope for this guide.

    Prerequisites

    • A Gate.AI API Key.
    • Python, Node.js, or curl installed (depending on the integration method you choose).

    What you’ll be able to do after completing this guide

    After completing this Gate.AI API quick start guide, you’ll be able to successfully send chat completion requests to Gate.AI using your chosen Python, Node.js, or curl method.

    You don’t need to complete examples in all three languages. Just choose the path that matches your application environment. The examples use Gate.AI’s OpenAI-compatible Base URL and chat completion format, based on the product version as of June 2026. For product background, visit Gate.AI product page.

    Step 1: Set up common Gate.AI API configuration

    This step prepares the common API configuration parameters for all integration paths.

    Action:

    Before choosing an implementation path, use the following Gate.AI API configuration parameters.

    Configuration item Value
    API Key YOUR_GATEAI_API_KEY
    Base URL xx/openai/v1
    Chat completions endpoint xx/openai/v1/chat/completions
    Python example model value auto
    Node.js example model value auto
    curl example model value deepseek/deepseek-v3.2

    The API key is used for request authentication. The Base URL routes calls from OpenAI-compatible SDKs to Gate.AI. For the curl path, you must use the Endpoint directly.

    Step 2: Choose an API integration path

    This step ensures the Python, Node.js, and curl examples aren’t mistaken as all required to run.

    Action:

    Pick one path from the table below.

    Integration path Suitable scenarios Required environment Next step
    Python Your app, scripts, or backend uses Python Python and OpenAI Python SDK Step 3A
    Node.js Your app or service uses JavaScript or Node.js Node.js and OpenAI Node.js SDK Step 3B
    curl You need to test directly in the terminal or debug REST requests curl Step 3C

    Completing just one path is enough to verify your Gate.AI API integration. Only run multiple paths if you need to test Gate.AI across multiple development environments.

    Step 3A: Send a Python chat completion request

    This path uses the OpenAI Python SDK and specifies the Gate.AI Base URL.

    Action:

    Use this path only if your environment is Python.

    1. from openai import OpenAI
    2. client = OpenAI(
    3. api_key="YOUR_GATEAI_API_KEY",
    4. base_url="https://api.gate.ai/openai/v1",
    5. )
    6. completion = client.chat.completions.create(
    7. model="auto",
    8. messages=[
    9. {"role": "system", "content": "system prompt"},
    10. {"role": "user", "content": "how are you?"}
    11. ],
    12. )
    13. print(completion.choices[0].message.content)

    You’ll see the assistant’s reply in your terminal, for example:

    1. Hello! Nice to meet you. How can I help you?

    This path keeps the OpenAI Python SDK request structure. You only replace the API key and Base URL with Gate.AI.

    Step 3B: Send a Node.js chat completion request

    This path uses the OpenAI Node.js SDK and specifies the Gate.AI Base URL.

    Action:

    Use this path only if your environment is Node.js.

    1. const OpenAI = require("openai")
    2. const client = new OpenAI({
    3. apiKey: "YOUR_GATEAI_API_KEY",
    4. baseURL: "https://api.gate.ai/openai/v1",
    5. })
    6. async function main() {
    7. const completion = await client.chat.completions.create({
    8. model: "auto",
    9. messages: [
    10. {"role": "system", "content": "system prompt"},
    11. {"role": "user", "content": "how are you?"}
    12. ],
    13. })
    14. console.log(completion.choices[0].message.content)
    15. }
    16. main()

    You’ll see the assistant’s reply in the console. If your script prints nothing when it runs, print the full completion object to confirm that the choices[0].message.content field exists.

    Step 3C: Send a curl chat completion request

    This path doesn’t require an SDK. You call the Gate.AI chat completions endpoint directly.

    Action:

    Use this path only when you want to send a REST request directly from the terminal.

    1. curl --location --request POST 'https://api.gate.ai/openai/v1/chat/completions' \
    2. --header 'Authorization: Bearer YOUR_GATEAI_API_KEY' \
    3. --header 'Content-Type: application/json' \
    4. --data-raw '{
    5. "model": "deepseek/deepseek-v3.2",
    6. "stream": false,
    7. "messages": [
    8. {
    9. "role": "user",
    10. "content": "how are you"
    11. }
    12. ]
    13. }'

    You’ll receive a JSON response that includes the choices array. The assistant’s reply is in choices[0].message.content.

    Example: Successful Gate.AI API response

    A successful Gate.AI chat completion response follows the OpenAI-compatible structure.

    1. {
    2. "id": "243c850e-214c-431e-977f-ebaf4aa95f56",
    3. "choices": [
    4. {
    5. "index": 0,
    6. "message": {
    7. "role": "assistant",
    8. "content": "Hello! Nice to meet you. How can I help you?"
    9. },
    10. "finish_reason": "stop"
    11. }
    12. ],
    13. "created": 1773408946,
    14. "model": "deepseek.v3-v1:0",
    15. "object": "chat.completion",
    16. "usage": {
    17. "prompt_tokens": 5,
    18. "completion_tokens": 15,
    19. "total_tokens": 20
    20. }
    21. }
    Response field What to check
    choices[0].message.content The generated assistant reply content
    finish_reason Whether the model stopped normally
    model The model actually used for the request
    usage.prompt_tokens Number of tokens consumed by the input messages
    usage.completion_tokens Number of tokens consumed by the assistant reply
    usage.total_tokens Total number of tokens consumed by the request and reply

    For quick testing, the most critical field is choices[0].message.content. The usage object helps confirm that Gate.AI processed the prompt and generated the reply as expected.

    Common reasons for failed Gate.AI API requests and troubleshooting

    • Symptom: The request returns an authentication error.
      • Cause: API key missing, expired, incorrect format, or not copied correctly from Gate.AI.
      • Fix: Replace YOUR_GATEAI_API_KEY with a valid Gate.AI API key. For curl, keep the header format Authorization: Bearer YOUR_GATEAI_API_KEY.
    • Symptom: The SDK request is sent to the wrong service.
      • Cause: The OpenAI SDK is still using the default Base URL.
      • Fix: In Python, set base_url. In Node.js, set baseURL to https://api.gate.ai/openai/v1, then send the request again.
    • Symptom: The response doesn’t use the expected model.
      • Cause: You used auto, or Gate.AI mapped it to a different model ID during automatic model selection.
    • Symptom: The script runs but prints nothing.
      • Cause: The code doesn’t read completion.choices[0].message.content, or the request failed before printing.

    Next steps: configurable or integrable items

    After completing any Gate.AI quick start API path, you can integrate the same Gate.AI Base URL into your application backend, developer tools, internal automation, or testing workflows.

    Recommended follow-up topics:

    FAQs

    Do I need to run Python, Node.js, and curl at the same time?

    No. Choose one integration path based on your development environment. Python, Node.js, and curl are just different ways to send Gate.AI chat completion requests.

    Why does Python use base_url, while Node.js uses baseURL?

    The Python SDK uses snake_case naming, while the Node.js SDK uses camelCase naming. Both point to the same Gate.AI Base URL.

    Can I use model="auto" for every request?

    You can use auto when you want Gate.AI to automatically select a model and your configuration supports it. If you want to specify a model, refer to the Gate.AI documentation for the model ID you want to use.

    Where is the assistant reply in the JSON output?

    The assistant reply is in choices[0].message.content. Token usage is shown separately in the usage object.

    The content herein does not constitute any offer, solicitation, or recommendation. You should always seek independent professional advice before making any investment decisions. Please note that Gate may restrict or prohibit the use of all or a portion of the Services from Restricted Locations. For more information, please read the User Agreement