Zhizengzeng API Documentation

repository·main·Indexed 21 days ago

https://github.com/xing61/ztoken-pro

Enterprise-grade proxy service providing stable access to major LLMs including OpenAI, Claude, Gemini, xAI, and various Chinese models. It features OpenAI-compatible interfaces supporting GPT-4o, Batch API, Assistant API, Fine-tuning, DALL-E-3, Whisper, and TTS. The service integrates with the OpenAI Python SDK and Langchain via a custom base URL (https://api.zhizengzeng.com/v1/).

Tokens
2.5K
Snippets
12
Records
13
Agent score
76%

What's inside ztoken-pro

  1. Overview of Zhizengzeng API Services

    main

    Zhizengzeng API provides enterprise-grade, stable access to various large language models (LLMs) including OpenAI, Anthropic (Claude), Google (Gemini), xAI (Grok), and domestic Chinese models like Baidu Wenxin Yiyan, Alibaba, Xunfei Xinghuo, and Zhipu ChatGLM.

    Key features include:

    • OpenAI Compatibility: Supports OpenAI-style interfaces for models like GPT-4o, GPT-3.5, and specialized features like Batch, Assistant API, Fine-tuning, DALL-E-3, Whisper (transcription/translation), and TTS (text-to-speech).
    • Multi-Model Support: Direct access to Claude, Gemini, and xAI official interface formats.
    • Developer Tools: Supports Embeddings (compatible with Langchain, vector databases, AutoGPT), Function Calling, and Streaming mode.
    • Ease of Use: No need for personal OpenAI accounts or US-based bank cards; supports WeChat recharge and corporate payments.
  2. Create a fine-tuning job

    main

    Once you have a file_id from an uploaded training file, you can initiate a fine-tuning job using openai.FineTuningJob.create. You must specify the training_file (the file ID) and the base model you wish to fine-tune (e.g., "gpt-3.5-turbo").

    API_SECRET_KEY = "api-key"
    BASE_URL = "https://api.zhizengzeng.com/v1"
    
    # jobs
    def jobs(file_id):
        openai.api_key = API_SECRET_KEY
        openai.api_base = BASE_URL
        resp = openai.FineTuningJob.create(training_file=file_id, model="gpt-3.5-turbo")  
        print(resp)
  3. Configure Authentication and Base URL

    main

    All API requests must be made via HTTP. To authenticate, you must include your unique API_KEY (obtained from the Zhizengzeng management backend) in the HTTP Authorization header.

    Base URL: https://api.zhizengzeng.com/ (supports HTTPS)

    Required HTTP Headers:

    Content-Type: application/json
    Authorization: Bearer YOUR_API_KEY
    Content-Type: application/json
    Authorization: Bearer sk-******
  4. Retrieve batch results

    main

    After a batch job is complete, you can retrieve the output content using client.files.content(fid). Note that you use the file ID associated with the batch results to access the text content.

    API_SECRET_KEY = "api-key";
    BASE_URL = "https://api.zhizengzeng.com/v1"; 
    
    def get_result(fid):
        client = OpenAI(api_key=API_SECRET_KEY, base_url=BASE_URL)
        content = client.files.content(fid)
        print(content.text)
  5. Upload training data for fine-tuning

    main

    To prepare for fine-tuning, you must first upload your training data (typically in .jsonl format) to the server using the openai.File.create method. Set the purpose parameter to 'fine-tune'. This returns a file ID which is required for creating a fine-tuning job.

    API_SECRET_KEY = "api-key"
    BASE_URL = "https://api.zhizengzeng.com/v1"
    
    def files():
        openai.api_key = API_SECRET_KEY
        openai.api_base = BASE_URL
        resp = openai.File.create(
            file=open("mydata.jsonl", "rb"),
            purpose='fine-tune'
        )
        print(resp)
  6. Upload batch data files

    main

    To use the batch API, you must first upload your data in .jsonl format. Use the client.files.create method with purpose='batch' to upload the file. This returns a file ID which is required for creating a batch job.

    API_SECRET_KEY = "api-key";
    BASE_URL = "https://api.zhizengzeng.com/v1"; 
    
    def files():
        client = OpenAI(api_key=API_SECRET_KEY, base_url=BASE_URL)
        resp = client.files.create(
            file=open("test.jsonl", "rb"),
            purpose='batch'
        )
        print(resp)
        return resp.id
  7. Use a fine-tuned model for chat completions

    main

    After a fine-tuning job is complete, you can use the resulting model in chat completions. Pass the specific fine-tuned model ID (e.g., "ft:gpt-3.5-turbo-0613xxxxxxxxxxxxxxxxxxx") to the model parameter in openai.ChatCompletion.create.

    API_SECRET_KEY = "api-key"
    BASE_URL = "https://api.zhizengzeng.com/v1"
    
    # chat
    def chat_completions(query):
        openai.api_key = API_SECRET_KEY
        openai.api_base = BASE_URL
        resp = openai.ChatCompletion.create(
            model="ft:gpt-3.5-turbo-0613xxxxxxxxxxxxxxxxxxx", 
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": query}
            ]
        )
        print(resp)
  8. Check batch status

    main

    To monitor the progress of a batch job, use client.batches.retrieve(bid) with the batch ID. This allows you to check if the batch has finished processing.

    API_SECRET_KEY = "api-key";
    BASE_URL = "https://api.zhizengzeng.com/v1"; 
    
    def retrieve(bid):
        client = OpenAI(api_key=API_SECRET_KEY, base_url=BASE_URL)
        resp = client.batches.retrieve(bid)
        print(resp)
        return resp.id
  9. Check the status of a fine-tuning job

    main

    To monitor the progress of a fine-tuning process, use openai.FineTuningJob.retrieve(ftid), where ftid is the unique identifier for the fine-tuning job.

    API_SECRET_KEY = "api-key"
    BASE_URL = "https://api.zhizengzeng.com/v1"
    
    # retrieve
    def retrieve(ftid):
        openai.api_key = API_SECRET_KEY
        openai.api_base = BASE_URL
        resp = openai.FineTuningJob.retrieve(ftid) 
        print(resp)
  10. Create a batch job

    main

    Once a file has been uploaded, you can initiate a batch job using client.batches.create. You must provide the input_file_id (obtained from the file upload step), the target endpoint (e.g., /v1/chat/completions), and a completion_window (e.g., 24h).

    API_SECRET_KEY = "api-key";
    BASE_URL = "https://api.zhizengzeng.com/v1"; 
    
    def batches(file_id):
        client = OpenAI(api_key=API_SECRET_KEY, base_url=BASE_URL)
        resp = client.batches.create(input_file_id=file_id,
                                     endpoint="/v1/chat/completions",
                                     completion_window="24h")
        print(resp)
        return resp.id
  11. Use Zhizengzeng API via Direct HTTP Requests

    main

    For any other programming language, you can make direct HTTP requests by targeting the Zhizengzeng endpoint and providing the API key in the header.

    1. URL: Use https://api.zhizengzeng.com/v1/ as the base for your requests (replacing https://api.openai.com/v1/).
    2. Header: Include Authorization: Bearer sk-******.
    curl https://api.zhizengzeng.com/v1/chat/completions \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer sk-******" \
      -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Hello!"}]}'
  12. Use Zhizengzeng API with the OpenAI Python SDK

    main

    You can use the official openai Python package by replacing the standard OpenAI configuration with Zhizengzeng's credentials.

    1. Set api_key to your Zhizengzeng API Key.
    2. Set base_url to https://api.zhizengzeng.com/v1/.
    from openai import OpenAI
    
    client = OpenAI(
        api_key="sk-******", # Replace with your Zhizengzeng API Key
        base_url="https://api.zhizengzeng.com/v1/"
    )