Prefix Completion - MyTokenGate
1. Use Cases
In prefix completion, the user provides the desired prefix information, allowing the model to complete the rest of the content based on the prefix provided by the user. With this capability, the model demonstrates better instruction-following abilities and can address user requirements for specific formats in certain scenarios.
2. How to Use
Add the extra_body parameter to your request:
extra_body={"prefix": "desired prefix content"}3. Supported Models
Most large language models support this parameter. For reasoning models like Qwen3 series, add enable_thinking=true to disable reasoning mode first. DeepSeek R1 series does not currently support this parameter.
View the full model list at Model List
4. Example Usage
Below is an example of using prefix completion with the OpenAI library:
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://gateway.mytokengate.com/v1"
)
messages = [
{"role": "user", "content": "Write a quick sort function"}
]
response = client.chat.completions.create(
model="gpt-4o",
messages=messages,
extra_body={"prefix": "```python\n"}
)
print(response.choices[0].message.content)Last updated on