Skip to content

How to use a custom OpenAI-compatible endpoint to replace the official OpenAI API. #4299

Description

@scientiacoder

🚀 The feature

Let's say we have an endpoint

curl --location 'https://llm-relay.group.cn/v1/chat/completions'
--header 'Authorization: Bearer sk-xxxxxxx'
--header 'Content-Type: application/json'
--data '{
"model": "gemini-3.1-pro-preview",
"messages": [
{
"role": "system",
"content": "string"
},
{
"role": "user",
"content": "hello"
}
]
}'

and it returns
{
"id": "chatcmpl-24b8a5994d2135c87ef73b5ef60a3d10",
"model": "gemini-3.1-pro-preview",
"object": "chat.completion",
"created": 1773219707,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 2,
"completion_tokens": 344,
"total_tokens": 346,
"prompt_tokens_details": {
"cached_tokens": 0,
"text_tokens": 2,
"audio_tokens": 0,
"image_tokens": 0
},
"completion_tokens_details": {
"text_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 335
},
"input_tokens": 0,
"output_tokens": 0,
"input_tokens_details": null,
"claude_cache_creation_5_m_tokens": 0,
"claude_cache_creation_1_h_tokens": 0
}
}

How to use this customized custom OpenAI-compatible endpoint to REPLACE the OFFICIAL OPEN-AI key since I don't have, thanks.

Motivation, pitch

It is convenient for us to use OpenAI-compatible endpoint instead of official OpenAI

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumAnnoying but has workaroundsenhancementNew feature or requestsdk-pythonPython SDK specific

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions