Skip to content

MaaS_Ge sdk request

Openai

from openai import OpenAI

client = OpenAI(
    api_key="YOUR AK",
    base_url="https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/"
)

resp = client.chat.completions.create(
    messages=[{
            "role": "user",
            "content": "who are you?"
        }],
    model= ""
)

print(resp.choices[0].message.content)

genai

from google import genai
from google.genai import types
import base64
import os

def generate():
    client = genai.Client(
        api_key="YOUR AK",
        vertexai=True,
        http_options={
            "base_url": "https://genaiapi.cloudsway.net/{endpointPath}"
        }
    )

    model = "gemini-3-pro-preview"
    # https://storage.googleapis.com/routify_proxy_file_bucket/33M_test.mp4  gs://routify_proxy_file_bucket/33M_test.mp4
    # msg1_video1 = types.Part.from_uri(
    #     file_uri="gs://routify_proxy_file_bucket/33M_test.mp4",
    #     mime_type="video/mp4",
    # )

    contents = [
        types.Content(
            role="user",
            parts=[
                # msg1_video1,
                types.Part.from_text(text="""hello""")
            ]
        ),
    ]

    generate_content_config = types.GenerateContentConfig(
      temperature = 1,
      top_p = 0.95,
      max_output_tokens = 65535,
      safety_settings = [types.SafetySetting(
        category="HARM_CATEGORY_HATE_SPEECH",
        threshold="OFF"
      ),types.SafetySetting(
        category="HARM_CATEGORY_DANGEROUS_CONTENT",
        threshold="OFF"
      ),types.SafetySetting(
        category="HARM_CATEGORY_SEXUALLY_EXPLICIT",
        threshold="OFF"
      ),types.SafetySetting(
        category="HARM_CATEGORY_HARASSMENT",
        threshold="OFF"
      )],
      thinking_config=types.ThinkingConfig(
        thinking_level="HIGH",
      ),
)

    for chunk in client.models.generate_content_stream(
      model = model,
      contents = contents,
      config = generate_content_config,
      ):
      print(chunk.text, end="")

generate()

Anthropic

import anthropic

client = anthropic.Anthropic(base_url="https://genaiapi.cloudsway.net/{endpointPath}",
                             api_key="YOUR AK")

message = client.beta.messages.create(
    model="xxx",
    max_tokens=4096,
    system="you are user",
    messages=[{"role": "user", "content": "who are you?"}],
    stream=True,
    thinking={
        "type": "enabled",
        "budget_tokens": 4000
    }

)

for chunk in message:
    print(chunk)