> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xingchaoyiqing.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GlobalAI OPC Quickstart: Your First API Call in Minutes

> Make your first text, image, and video generation API calls with GlobalAI OPC. Covers obtaining an API key, choosing a model, and polling for results.

This guide walks you through making your first API calls to GlobalAI OPC. By the end, you will have generated text with a GPT model, created an image with Nano Banana, and kicked off a Sora video generation — all using the same Bearer token authentication pattern.

<Note>
  Image and video generation are **asynchronous**. When you create a task, the API returns a task ID immediately. You must poll the result endpoint until the status changes to `completed` before you can access the generated file.
</Note>

<Steps>
  <Step title="Get an API Key">
    Contact the GlobalAI OPC team to obtain your API key. Once you have it, store it securely — never hard-code it in source files or commit it to version control.

    Set your key as an environment variable so your code can read it without embedding it in plain text:

    ```bash theme={null}
    export GLOBALAIOPC_API_KEY="your_api_key_here"
    ```

    <Tip>
      Add the `export` line to your shell profile (e.g. `~/.bashrc` or `~/.zshrc`) so the variable persists across sessions. For production environments, use a dedicated secrets manager such as AWS Secrets Manager, HashiCorp Vault, or your platform's built-in secrets store.
    </Tip>
  </Step>

  <Step title="Make a Text Generation Call">
    Send a chat completion request to the text API endpoint. The endpoint is fully OpenAI-compatible, so any code or SDK that works with OpenAI's `chat/completions` API works here with only a base URL change.

    <CodeGroup>
      ```bash cURL theme={null}
      curl -X POST http://apillm.globalaiopc.com/gw_llm_power/v1/chat/completions \
        -H "Authorization: Bearer $GLOBALAIOPC_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{
          "model": "gpt-5.4",
          "messages": [
            {
              "role": "user",
              "content": "Hello, introduce yourself"
            }
          ]
        }'
      ```

      ```python Python theme={null}
      import os
      import requests

      response = requests.post(
          "http://apillm.globalaiopc.com/gw_llm_power/v1/chat/completions",
          headers={
              "Authorization": f"Bearer {os.environ['GLOBALAIOPC_API_KEY']}",
              "Content-Type": "application/json",
          },
          json={
              "model": "gpt-5.4",
              "messages": [
                  {
                      "role": "user",
                      "content": "Hello, introduce yourself",
                  }
              ],
          },
      )

      data = response.json()
      print(data["choices"][0]["message"]["content"])
      ```
    </CodeGroup>

    A successful response looks like this:

    ```json theme={null}
    {
      "id": "chatcmpl-abc123",
      "object": "chat.completion",
      "created": 1761635478,
      "model": "gpt-5.4",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "Hi! I'm an AI assistant powered by GlobalAI OPC. I'm here to help you with questions, writing, analysis, and much more. How can I assist you today?"
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 12,
        "completion_tokens": 34,
        "total_tokens": 46
      }
    }
    ```
  </Step>

  <Step title="Generate an Image">
    Submit an image generation request to the Nano Banana endpoint. The API returns a task ID immediately — you will poll for the result in the next step.

    <Tip>
      Save the task `id` from the response right away. You'll need it to retrieve your generated image.
    </Tip>

    <CodeGroup>
      ```bash cURL theme={null}
      curl -X POST https://zcbservice.aizfw.cn/kyyReactApiServer/v1/banana/images \
        -H "Authorization: Bearer $GLOBALAIOPC_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{
          "model": "nano-banana-2",
          "prompt": "A cute orange cat sitting on a windowsill",
          "size": "16:9"
        }'
      ```

      ```python Python theme={null}
      import os
      import requests

      response = requests.post(
          "https://zcbservice.aizfw.cn/kyyReactApiServer/v1/banana/images",
          headers={
              "Authorization": f"Bearer {os.environ['GLOBALAIOPC_API_KEY']}",
              "Content-Type": "application/json",
          },
          json={
              "model": "nano-banana-2",
              "prompt": "A cute orange cat sitting on a windowsill",
              "size": "16:9",
          },
      )

      task = response.json()
      task_id = task["id"]
      print(f"Image task created: {task_id} — status: {task['status']}")
      ```
    </CodeGroup>

    The response confirms the task is queued:

    ```json theme={null}
    {
      "id": "abc123def456",
      "object": "image",
      "created": 1761635478,
      "model": "nano-banana-2",
      "status": "queued"
    }
    ```
  </Step>

  <Step title="Poll for the Image Result">
    Query the result endpoint with your task ID until the status is `completed`. The completed response includes a direct URL to your generated image.

    <Note>
      Poll every 30–60 seconds. Polling too frequently can result in rate limiting and doesn't speed up generation.
    </Note>

    <CodeGroup>
      ```bash cURL theme={null}
      curl -X GET https://zcbservice.aizfw.cn/kyyReactApiServer/v1/result/abc123def456 \
        -H "Authorization: Bearer $GLOBALAIOPC_API_KEY"
      ```

      ```python Python theme={null}
      import os
      import time
      import requests

      TASK_ID = "abc123def456"  # replace with your actual task ID
      HEADERS = {"Authorization": f"Bearer {os.environ['GLOBALAIOPC_API_KEY']}"}

      while True:
          response = requests.get(
              f"https://zcbservice.aizfw.cn/kyyReactApiServer/v1/result/{TASK_ID}",
              headers=HEADERS,
          )
          result = response.json()
          status = result.get("status")

          print(f"Status: {status}")

          if status == "completed":
              print("Image URL:", result["image_url"])
              break
          elif status == "failed":
              print("Generation failed:", result.get("error"))
              break

          time.sleep(30)
      ```
    </CodeGroup>

    When the image is ready, the response includes the image URL:

    ```json theme={null}
    {
      "id": "abc123def456",
      "object": "image",
      "status": "completed",
      "model": "nano-banana-2",
      "image_url": "https://cdn.example.com/generated/abc123def456.png"
    }
    ```
  </Step>

  <Step title="Generate a Video">
    Submit a video generation request to the Sora endpoint. Like image generation, this is asynchronous — the API returns a task ID that you poll until the video is ready.

    <Tip>
      Save the task `id` from the response immediately. Video generation can take several minutes, and you'll need the ID to retrieve your result.
    </Tip>

    ```bash cURL theme={null}
    curl -X POST https://zcbservice.aizfw.cn/kyyReactApiServer/v1/sora/videos \
      -H "Authorization: Bearer $GLOBALAIOPC_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "openAiSora2Plus",
        "prompt": "Ocean waves crashing on the shore",
        "aspect_ratio": "16:9",
        "seconds": 8
      }'
    ```

    The response confirms the task is queued:

    ```json theme={null}
    {
      "id": "vid789xyz012",
      "object": "video",
      "created": 1761635500,
      "model": "openAiSora2Plus",
      "status": "queued"
    }
    ```

    Poll for the video result using the same result endpoint:

    ```bash cURL theme={null}
    curl -X GET https://zcbservice.aizfw.cn/kyyReactApiServer/v1/result/vid789xyz012 \
      -H "Authorization: Bearer $GLOBALAIOPC_API_KEY"
    ```

    When the video is ready, the completed response includes the video URL:

    ```json theme={null}
    {
      "id": "vid789xyz012",
      "object": "video",
      "status": "completed",
      "model": "openAiSora2Plus",
      "video_url": "https://cdn.example.com/generated/vid789xyz012.mp4"
    }
    ```
  </Step>
</Steps>

## Next Steps

You've made your first text, image, and video generation calls. Explore the full API reference to discover all available models, parameters, and capabilities.

<CardGroup cols={2}>
  <Card title="Authentication" icon="key" href="/guides/authentication">
    Learn how to manage API keys and protect them with environment variables and secrets managers.
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/introduction">
    Browse every endpoint, request parameter, and response schema for all three API categories.
  </Card>
</CardGroup>
