Skip to Content

Text Generation - MyTokenGate

Language Model (LLM) User Manual

1. Model Core Capabilities

1.1 Basic Functions

Text Generation: Generate coherent natural language text based on context, supporting various styles and genres.

Semantic Understanding: Deeply parse user intent, supporting multi-round dialogue management to ensure the coherence and accuracy of conversations.

Knowledge Q&A: Cover a wide range of knowledge domains, including science, technology, culture, history, etc., providing accurate knowledge answers.

Code Assistance: Support code generation, explanation, and debugging for multiple mainstream programming languages (such as Python, Java, C++, etc.).

1.2 Advanced Capabilities

Long Text Processing: Current workhorse models support context windows up to roughly 1M tokens, suitable for long document generation and complex dialogue scenarios.

Instruction Following: Precisely understand complex task instructions, such as “compare A/B schemes using a Markdown table.”

Style Control: Adjust output style through system prompts, supporting various styles such as academic, conversational, and poetry.

Multimodal Support: In addition to text generation, support tasks such as image description and speech-to-text.

2. API Call Specifications

2.1 Basic Request Structure

You can make end-to-end API requests using the OpenAI SDK.

Generate Dialogue

from openai import OpenAI client = OpenAI(api_key="YOUR_KEY", base_url="https://gateway.mytokengate.com/v1") response = client.chat.completions.create( model="gpt-5.4", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Write a haiku about recursion in programming."} ], temperature=0.7, max_tokens=1024, stream=True ) for chunk in response: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True)

Analyze an Image

from openai import OpenAI client = OpenAI(api_key="YOUR_KEY", base_url="https://gateway.mytokengate.com/v1") response = client.chat.completions.create( model="gemini-3.1-pro-preview", messages=[ { "role": "user", "content": [ { "type": "image_url", "image_url": { "url": "https://example.com/image.png" } }, { "type": "text", "text": "What's in this image?" } ] } ], temperature=0.7, max_tokens=1024, stream=True ) for chunk in response: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True)

Generate JSON Data

import json from openai import OpenAI client = OpenAI( api_key="YOUR_KEY", base_url="https://gateway.mytokengate.com/v1" ) response = client.chat.completions.create( model="gpt-5.4", messages=[ {"role": "system", "content": "You are a helpful assistant designed to output JSON."}, {"role": "user", "content": "Who were the men's and women's singles champions of the 2020 Olympic table tennis? Respond in JSON format."} ], response_format={"type": "json_object"} ) print(response.choices[0].message.content)

2.2 Message Structure Explanation

Message TypeFunction DescriptionExample Content
systemModel instructions, defining the AI’s role and general behaviore.g., “You are a pediatrician with 10 years of experience.”
userUser input, passing the end user’s message to the modele.g., “How should a persistent fever in a toddler be treated?”
assistantModel-generated historical responses, providing examples of how it should respond to the current requeste.g., “I suggest measuring the temperature first…”

2.3 Responses API

Alongside POST /v1/chat/completions, the gateway exposes POST /v1/responses, following OpenAI’s Responses protocol. Both share the same models and the same billing; the choice depends on your client.

When Responses is required:

  • Calling the gpt-6 family with function tools. Those models reject /v1/chat/completions with tools and return a 400 that points at /v1/responses
  • Using Codex CLI 0.95 or later, which only speaks the Responses protocol

For everything else, chat/completions is the safer default.

Stateless only. Passing previous_response_id returns 400 with previous_response_not_supported, because the server keeps no conversation state. Send the full history in input on each call and let your client manage context.

reasoning.effort differs from chat. The gpt-6 family accepts low, medium, high, xhigh, and max. Sending none or minimal is rejected upstream.

curl https://gateway.mytokengate.com/v1/responses \ -H "Authorization: Bearer $MYTOKENGATE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-6-astra", "input": "Explain prompt caching in three sentences", "reasoning": { "effort": "medium" } }'

The response carries an output array of content blocks; text lives in output[].content[].text. Usage is under usage with slightly different field names than chat (input_tokens rather than prompt_tokens).

3. Model Selection Guide

Claude Series

  • claude-fable-5 - Frontier, strongest
  • claude-sonnet-5 - Balanced default
  • claude-opus-4-8 - Previous frontier

GPT Series

  • gpt-5.6-sol - Flagship
  • gpt-5.4 - Everyday workhorse
  • gpt-5.5 - Previous-generation flagship

Gemini Series

  • gemini-3.1-pro-preview - Complex multimodal tasks
  • gemini-3.5-flash - Near-Pro intelligence, Flash price
  • gemini-3-flash-preview - Fast response

4. Detailed Explanation of Core Parameters

4.1 Creativity Control

# Temperature parameter (0.0~2.0) temperature=0.5 # Balances creativity and reliability # Nucleus sampling (top_p) top_p=0.9 # Considers only the top 90% probability cumulative word set

4.2 Output Limits

max_tokens=1000 # Maximum generation length per request stop=["\n##", "<|end|>"] # Stop sequences frequency_penalty=0.5 # Suppresses repetitive word usage (-2.0~2.0) stream=True # Stream output

4.3 Common Issues with Language Model Scenarios

  1. Model Output Garbled

Try setting parameters like temperature, top_k, top_p, and frequency_penalty.

payload = { "model": "gpt-5.4", "messages": [ {"role": "user", "content": "1+1=?"} ], "max_tokens": 200, "temperature": 0.7, "top_k": 50, "top_p": 0.7, "frequency_penalty": 0 }
  1. Explanation of max_tokens

It is recommended to reserve around 10k as space for input content.

  1. Output Truncation Issues
  • Set max_token to an appropriate value
  • Use stream requests for long outputs
  • Increase client timeout
  1. Error Code Handling
Error CodeCommon CauseSolution
400Parameter format errorCheck parameter ranges
401API Key not correctly setVerify the API Key
403Insufficient permissionsRefer to error messages
429Request rate limit exceededImplement exponential backoff retry
503/504Model overloadSwitch to backup model nodes

5. Billing and Quota Management

5.1 Billing Formula

Total Cost = (Input Tokens × Input Unit Price) + (Output Tokens × Output Unit Price)

6. Application Scenarios

6.1 Technical Documentation Generation

from openai import OpenAI client = OpenAI(api_key="YOUR_KEY", base_url="https://gateway.mytokengate.com/v1") response = client.chat.completions.create( model="claude-sonnet-5", messages=[{ "role": "user", "content": "Write a Python tutorial on asynchronous web scraping, including code examples and precautions." }], temperature=0.7, max_tokens=4096 )

6.2 Data Analysis Reports

from openai import OpenAI client = OpenAI(api_key="YOUR_KEY", base_url="https://gateway.mytokengate.com/v1") response = client.chat.completions.create( model="gemini-3.1-pro-preview", messages=[ {"role": "system", "content": "You are a data analysis expert. Output results in Markdown."}, {"role": "user", "content": "Analyze the sales trends of new energy vehicles in 2023."} ], temperature=0.7, max_tokens=4096 )
Last updated on