示例项目
    示例项目
    • Introduction (Must Read)
    • OpenAI official library usage tutorial
    • Obtain Base URL and API Key
    • OpenAI
      • Chat
        POST
      • Chat (o1,o3,o4 series model)
        POST
      • dall--e-3
        POST
      • gpt-image-1
        POST
      • Image edit
        POST
      • Analyze image
        POST
      • Analyze PDF
        POST
    • Gemini
      • gemini
        POST

    OpenAI official library usage tutorial

    📌
    Our API is fully compatible with the OpenAI interface protocol and supports seamless integration with various applications that utilize the OpenAI interface.
    Note: All chat models (including non-OpenAI models) support the official OpenAI library. Please ensure that the request URL and format adhere to OpenAI's request method.
    Reference: Official development documentation.
    When making requests to the interface, replace https://api.openai.com with our API address (which can be found in the API website -> Console). Your KEY must correspond with the API website, so be careful not to mix up mixed sites with official transition sites.

    OpenAI official Python library#

    Official project address
    ⚠️ Note: Please upgrade the openai library to version 1.25+ or the latest version, otherwise any call errors will not be supported.

    Installation#

    pip install openai

    DEMO:#

    Note: base_url needs to include the /v1/ suffix.
    import os
    import openai
    
    openai.api_key = "apikey"
    
    openai.base_url = "https://api.getgoapi.com/v1/"
    openai.default_headers = {"x-foo": "true"}
    
    completion = openai.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[
            {
                "role": "user",
                "content": "Hello world!",
            },
        ],
    )
    print(completion.choices[0].message.content)
    
    #It usually outputs results.:Hello there! How can I assist you today ?`
    修改于 2025-05-22 03:58:27
    上一页
    Introduction (Must Read)
    下一页
    Obtain Base URL and API Key
    Built with