1. Chat
Nebula-API操作文档
🇺🇸English
  • 🇨🇳中文
  • 🇺🇸English
  • Chat
    • General Text Dialogue Interface Document
    • Tongyi Qianwen General Dialogue Interface Document
    • DeepSeek General Dialogue Document
    • GPT Chat General Dialogue Document
    • Grok Model (xAI) General Dialogue Interface Document
  • Image
    • General Image Generation Interface Document
    • Nano Banana Image Generation Interface Document
    • Tongyi Qianwen Text to Image Model Interface Document
    • Tongyi Qianwen Image Editing Model Interface Document
  • Video
    • Sora-2 interface document
    • Alibaba Wanxiang Wan2.5 Tu Sheng Video Interface Document
    • Google Veo Video Model Interface Document
    • General Video Generation Interface Document
  • AI App
    • Cherry Studio Integration Guide
    • LangChain Development Framework Integration Guide
    • Cursor Code Editor Integration Guide
    • Claude Code and other client integration guidelines
    • Cline (VS Code) AI Programming Assistant Integration Guide
    • Immersive Translation Integration Guide
  • Real time conversation
    • Realtime real-time conversation document
  1. Chat

General Text Dialogue Interface Document

1. Introduction#

This interface generates dialogue answers by calling OpenAI compatible large language models, supports preset system roles to interact with user questions, and returns the Chinese reply content generated by the model. The core function is to generate responses from the model that conform to the system role settings based on user input questions.

2. request parameters#

parameter nametypenecessaryInstructionsexample value
api_keystringyesAccess API key for authentication purposessk - XyLy**************************mIqSt
base_urlstringyesThe basic address of the API service, specifying the access path for the model servicehttps://llm.ai-nebula.com
modelstringyesLarge language model identification for generating answersclaude - sonnet - 4 - 20250514 GPT-4o
messagesarrayyewDialogue message list, including system role definitions and user questions
Each element is an object, including:
- role:role(user/system/assistant)
- content:message content
{ "role": "user", "content": "hello" }
temperaturenumberNoControl the randomness of generated content, with higher 0-2 values indicating stronger response randomness0.7

3. Return Value Description#

The function returns a result of string type, which includes two possibilities:

(1) Successful Response#

Type: String
Description: The Chinese response content generated by the model
Example:
Artificial intelligence is a new technical science that researches and develops theories, methods, technologies, and application systems for simulating, extending, and expanding human intelligence. It attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a manner similar to human intelligence.

(2) Error Response#

Type: String
Description: A description containing the cause of the error. Possible situations:
Error: API key is invalid or unauthorized (key verification failed)
Error: Model claude-sonnet-4-20250514 does not exist or is not supported (model does not exist)
Error: Unable to connect to the API server (network or address error)
API request failed: [specific error information] (other API layer errors)
Unknown error occurred: [specific error information] (uncaught exception)

4. Error Handling#

The function captures and handles the following exception types (based on the OpenAI Python SDK exception system):
Exception TypeTrigger ScenarioReturn Message
AuthenticationErrorAPI key is invalid, expired, or unauthorizedError: API key is invalid or unauthorized
NotFoundErrorThe specified model ID does not exist or is not supported by the serverError: Model [model name] does not exist or is not supported
APIConnectionErrorNetwork interruption, base_url error, or server unresponsiveError: Unable to connect to the API server
APIErrorServer-side exceptions such as API request format errors, insufficient permissions, etc.API request failed: [error details]
Other Uncaught ExceptionsCode logic errors, unexpected data formats, etc.Unknown error occurred: [error details]

5. Implementation Code#

6. Usage Example Output#

(1) Successful Output Example#

AI Response Content:
Artificial intelligence is a new technical science that researches and develops theories, methods, technologies, and application systems for simulating, extending, and expanding human intelligence. Its core includes fields such as machine learning, natural language processing, and computer vision. It is widely applied in industries like healthcare, finance, and transportation, and is profoundly changing human production and lifestyles.

(2) Error Output Example#

AI Response Content:
Error: API key is invalid or unauthorized

7. Important Notes#

1.
Parameters such as api_key, base_url, and model in the code are required values. If modifications are needed, please adjust the corresponding fields directly within the function.
2.
The messages list contains conversation history; the system role is used to set model behavior, and the user role represents the current user question.
3.
It is recommended to set the temperature parameter between 0 and 2, where 0 indicates more deterministic generated content, and 2 indicates greater randomness.
4.
Network stability significantly affects the success rate of API calls; it is recommended to use this function in a good network environment.
5.
To extend to multi-turn conversation, modify the messages parameter by appending historical conversation records (including responses from the assistant role).
6.
The code depends on the openai Python library; please ensure it is installed before use (pip install openai).
修改于 2025-12-04 07:48:10
下一页
Tongyi Qianwen General Dialogue Interface Document
Built with